mirror of
https://github.com/maputnik/editor.git
synced 2026-08-24 22:17:25 +00:00
Ensure GeoJSON styling works
This commit is contained in:
@@ -32,7 +32,7 @@ class FontInput extends React.Component {
|
|||||||
/>
|
/>
|
||||||
})
|
})
|
||||||
|
|
||||||
return <div style={{display: 'inline-block', width: '51%'}}>
|
return <div style={{display: 'inline-block'}}>
|
||||||
{inputs}
|
{inputs}
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,9 +18,9 @@
|
|||||||
"url": "https://free.tilehosting.com/data/v3.json?key=25ItXg7aI5wurYDtttD",
|
"url": "https://free.tilehosting.com/data/v3.json?key=25ItXg7aI5wurYDtttD",
|
||||||
"title": "OpenMapTiles CDN"
|
"title": "OpenMapTiles CDN"
|
||||||
},
|
},
|
||||||
"swissnames-landscape": {
|
"naturalearth-airports": {
|
||||||
"type": "geojson",
|
"type": "geojson",
|
||||||
"data": "http://swissnames.lukasmartinelli.ch/data/landscape.geojson",
|
"data": "https://d2ad6b4ur7yvpq.cloudfront.net/naturalearth-3.3.0/ne_10m_airports.geojson",
|
||||||
"title": "Landscape Names GeoJSON"
|
"title": "NaturalEarth Airports GeoJSON"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ export default class LayerWatcher {
|
|||||||
const previousVectorLayers = { ...this._vectorLayers }
|
const previousVectorLayers = { ...this._vectorLayers }
|
||||||
|
|
||||||
Object.keys(this._sources).forEach(sourceId => {
|
Object.keys(this._sources).forEach(sourceId => {
|
||||||
this._sources[sourceId].forEach(vectorLayerId => {
|
(this._sources[sourceId] || []).forEach(vectorLayerId => {
|
||||||
const knownProperties = this._vectorLayers[vectorLayerId] || {}
|
const knownProperties = this._vectorLayers[vectorLayerId] || {}
|
||||||
const params = { sourceLayer: vectorLayerId }
|
const params = { sourceLayer: vectorLayerId }
|
||||||
map.querySourceFeatures(sourceId, params).forEach(feature => {
|
map.querySourceFeatures(sourceId, params).forEach(feature => {
|
||||||
|
|||||||
+25
-6
@@ -27,10 +27,9 @@ function assignVectorLayerColor(layerId) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function circleLayer(source, vectorLayer, color) {
|
function circleLayer(source, vectorLayer, color) {
|
||||||
return {
|
const layer = {
|
||||||
id: `${source}_${vectorLayer}_circle`,
|
id: `${source}_${vectorLayer}_circle`,
|
||||||
source: source,
|
source: source,
|
||||||
'source-layer': vectorLayer,
|
|
||||||
type: 'circle',
|
type: 'circle',
|
||||||
paint: {
|
paint: {
|
||||||
'circle-color': color,
|
'circle-color': color,
|
||||||
@@ -38,13 +37,16 @@ function circleLayer(source, vectorLayer, color) {
|
|||||||
},
|
},
|
||||||
filter: ["==", "$type", "Point"]
|
filter: ["==", "$type", "Point"]
|
||||||
}
|
}
|
||||||
|
if(vectorLayer) {
|
||||||
|
layer['source-layer'] = vectorLayer
|
||||||
|
}
|
||||||
|
return layer
|
||||||
}
|
}
|
||||||
|
|
||||||
function polygonLayer(source, vectorLayer, color, fillColor) {
|
function polygonLayer(source, vectorLayer, color, fillColor) {
|
||||||
return {
|
const layer = {
|
||||||
id: `${source}_${vectorLayer}_polygon`,
|
id: `${source}_${vectorLayer}_polygon`,
|
||||||
source: source,
|
source: source,
|
||||||
'source-layer': vectorLayer,
|
|
||||||
type: 'fill',
|
type: 'fill',
|
||||||
paint: {
|
paint: {
|
||||||
'fill-color': fillColor,
|
'fill-color': fillColor,
|
||||||
@@ -53,13 +55,16 @@ function polygonLayer(source, vectorLayer, color, fillColor) {
|
|||||||
},
|
},
|
||||||
filter: ["==", "$type", "Polygon"]
|
filter: ["==", "$type", "Polygon"]
|
||||||
}
|
}
|
||||||
|
if(vectorLayer) {
|
||||||
|
layer['source-layer'] = vectorLayer
|
||||||
|
}
|
||||||
|
return layer
|
||||||
}
|
}
|
||||||
|
|
||||||
function lineLayer(source, vectorLayer, color) {
|
function lineLayer(source, vectorLayer, color) {
|
||||||
return {
|
const layer = {
|
||||||
id: `${source}_${vectorLayer}_line`,
|
id: `${source}_${vectorLayer}_line`,
|
||||||
source: source,
|
source: source,
|
||||||
'source-layer': vectorLayer,
|
|
||||||
layout: {
|
layout: {
|
||||||
'line-join': 'round',
|
'line-join': 'round',
|
||||||
'line-cap': 'round'
|
'line-cap': 'round'
|
||||||
@@ -70,6 +75,10 @@ function lineLayer(source, vectorLayer, color) {
|
|||||||
},
|
},
|
||||||
filter: ["==", "$type", "LineString"]
|
filter: ["==", "$type", "LineString"]
|
||||||
}
|
}
|
||||||
|
if(vectorLayer) {
|
||||||
|
layer['source-layer'] = vectorLayer
|
||||||
|
}
|
||||||
|
return layer
|
||||||
}
|
}
|
||||||
|
|
||||||
export function colorHighlightedLayer(layer) {
|
export function colorHighlightedLayer(layer) {
|
||||||
@@ -110,6 +119,16 @@ export function generateColoredLayers(sources) {
|
|||||||
|
|
||||||
Object.keys(sources).forEach(sourceId => {
|
Object.keys(sources).forEach(sourceId => {
|
||||||
const layers = sources[sourceId]
|
const layers = sources[sourceId]
|
||||||
|
|
||||||
|
// Deal with GeoJSON sources that do not have any source layers
|
||||||
|
if(!layers) {
|
||||||
|
const color = Color(assignVectorLayerColor(sourceId))
|
||||||
|
circleLayers.push(circleLayer(sourceId, null, color.alpha(0.3).string()))
|
||||||
|
lineLayers.push(lineLayer(sourceId, null, color.alpha(0.3).string()))
|
||||||
|
polyLayers.push(polygonLayer(sourceId, null, color.alpha(0.2).string(), color.alpha(0.05).string()))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
layers.forEach(layerId => {
|
layers.forEach(layerId => {
|
||||||
const color = Color(assignVectorLayerColor(layerId))
|
const color = Color(assignVectorLayerColor(layerId))
|
||||||
circleLayers.push(circleLayer(sourceId, layerId, color.alpha(0.3).string()))
|
circleLayers.push(circleLayer(sourceId, layerId, color.alpha(0.3).string()))
|
||||||
|
|||||||
Reference in New Issue
Block a user