Skip to content

Commit e94cd7b

Browse files
committed
fix: Layers
1 parent 2587d79 commit e94cd7b

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

src/LayersControl.tsx

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { trans } from "./i18n/comps";
1515
import { Divider } from "antd"
1616

1717

18-
function layerSourceControl() {
18+
export function SourceControl() {
1919
// const childrenMap: any =
2020
const childrenMap: any = {
2121
url: stringSimpleControl(),
@@ -35,7 +35,7 @@ function layerSourceControl() {
3535
};
3636

3737
//Class is rebuiled not retuning same class
38-
class LayerSourceTemp extends new MultiCompBuilder(childrenMap, (props: any) => props)
38+
class SourceTemp extends new MultiCompBuilder(childrenMap, (props: any) => props)
3939
.setPropertyViewFn((children: any) => (<></>))
4040
.build() {
4141

@@ -117,7 +117,7 @@ function layerSourceControl() {
117117
);
118118
}
119119
}
120-
return LayerSourceTemp;
120+
return SourceTemp;
121121
}
122122

123123
var LayerObjectOption = new MultiCompBuilder(
@@ -135,7 +135,7 @@ var LayerObjectOption = new MultiCompBuilder(
135135
{ label: "arcgis-mapserver-tile", value: "arcgis mapserver tile" },
136136
{ label: "arcgis-mapserver-image", value: "arcgis mapserver image" }
137137
]),
138-
source: layerSourceControl(),
138+
source: SourceControl(),
139139
visible: withDefault(BoolPureControl, true),
140140
selectable: withDefault(BoolPureControl, true),
141141
userVisible: withDefault(BoolPureControl, true),
@@ -186,12 +186,9 @@ LayerObjectOption = class extends LayerObjectOption {
186186
}
187187
};
188188

189-
190-
//TODO: Change this to a function so it can be used directly instead of data
191-
192189
export function layersControl(config?: any) {
193190
const manualOptions = config ? config : [
194-
{ label: "Test", title: "test" }
191+
{ label: "Layer1", title: "Layer" }
195192
]
196193
const childrenMap: any = {
197194
data: manualOptionsControl(LayerObjectOption, {

src/vendors/helpers/Layers.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ export function createLayer(layerConfig, map) {
104104
}),
105105
});
106106
case 'geojson':
107-
console.log(JSON.stringify(layerConfig.source?.data || {}))
108107
return new VectorLayer({
109108
name: layerConfig.label,
110109
title: layerConfig.title || layerConfig.name,
@@ -119,11 +118,15 @@ export function createLayer(layerConfig, map) {
119118
splitscreen: layerConfig.splitscreen,
120119
displayInLayerSwitcher: layerConfig.userVisible,
121120
source: new VectorSource({
122-
features: new GeoJSON().readFeatures(JSON.stringify(layerConfig.source?.data || {}), {
121+
features: new GeoJSON().readFeatures(
122+
(typeof layerConfig.source.data == "string") ?
123+
layerConfig.source.data :
124+
JSON.stringify(layerConfig.source.data || {}), {
123125
// Ensure the features are read with the correct projection
124126
dataProjection: layerConfig.source.projection || 'EPSG:4326', // Assuming the GeoJSON is in WGS 84
125127
featureProjection: map.getView().getProjection() || 'EPSG:3857' // Assuming the map projection
126-
}),
128+
})
129+
127130
}),
128131
// Add this line to apply a generic style to the layer
129132
style: geoJsonStyleFunction
@@ -255,9 +258,15 @@ export function findLayer(map, name) {
255258
}
256259

257260
export function setFeatures(map, data, name, clear) {
261+
258262
const layer = findLayer(map, name);
259263
if (layer) {
260264
const source = layer.getSource()
265+
const reader = (source.getFormat ? source.getFormat() : null) || new GeoJSON({
266+
dataProjection: source.get('projection') || 'EPSG:4326', // Assuming the GeoJSON is in WGS 84,
267+
featureProjection: map.getView().getProjection() || 'EPSG:3857' // Assuming the map projection
268+
})
269+
261270
//Check if there is a undo stack connected to this source, if so clear and disable
262271
var undos = []
263272
//Disable all undo stacks
@@ -273,7 +282,6 @@ export function setFeatures(map, data, name, clear) {
273282
source.clear()
274283
undos.forEach((c) => { c.clear() })
275284
}
276-
const reader = (source.getFormat ? source.getFormat() : null) || new GeoJSON()
277285
if (reader && data) {
278286
//Now add the features based on types
279287
if (Array.isArray(data)) {

0 commit comments

Comments
 (0)