mirror of
https://github.com/maputnik/editor.git
synced 2026-06-15 11:47:26 +00:00
Inspection map is now always aware of current layer
This commit is contained in:
+48
-15
@@ -28,10 +28,9 @@ function assignVectorLayerColor(layerId) {
|
||||
|
||||
function circleLayer(source, vectorLayer, color) {
|
||||
return {
|
||||
id: vectorLayer + Math.random(),
|
||||
id: `${source}_${vectorLayer}_circle`,
|
||||
source: source,
|
||||
'source-layer': vectorLayer,
|
||||
interactive: true,
|
||||
type: 'circle',
|
||||
paint: {
|
||||
'circle-color': color,
|
||||
@@ -41,15 +40,14 @@ function circleLayer(source, vectorLayer, color) {
|
||||
}
|
||||
}
|
||||
|
||||
function polygonLayer(source, vectorLayer, color) {
|
||||
function polygonLayer(source, vectorLayer, color, fillColor) {
|
||||
return {
|
||||
id: vectorLayer + Math.random(),
|
||||
id: `${source}_${vectorLayer}_polygon`,
|
||||
source: source,
|
||||
'source-layer': vectorLayer,
|
||||
interactive: true,
|
||||
type: 'fill',
|
||||
paint: {
|
||||
'fill-color': Color(color).alpha(0.15).string(),
|
||||
'fill-color': fillColor,
|
||||
'fill-antialias': true,
|
||||
'fill-outline-color': color,
|
||||
},
|
||||
@@ -59,30 +57,65 @@ function polygonLayer(source, vectorLayer, color) {
|
||||
|
||||
function lineLayer(source, vectorLayer, color) {
|
||||
return {
|
||||
id: vectorLayer + Math.random(),
|
||||
id: `${source}_${vectorLayer}_line`,
|
||||
source: source,
|
||||
'source-layer': vectorLayer,
|
||||
interactive: true,
|
||||
layout: {
|
||||
'line-join': 'round',
|
||||
'line-cap': 'round'
|
||||
},
|
||||
type: 'line',
|
||||
paint: {'line-color': color},
|
||||
paint: {
|
||||
'line-color': color,
|
||||
},
|
||||
filter: ["==", "$type", "LineString"]
|
||||
}
|
||||
}
|
||||
|
||||
export function colorHighlightedLayer(layer) {
|
||||
if(!layer || layer.type === 'background' || layer.type === 'raster') return null
|
||||
|
||||
function changeFilter(l) {
|
||||
if(layer.filter) {
|
||||
l.filter = layer.filter
|
||||
} else {
|
||||
delete l['filter']
|
||||
}
|
||||
return l
|
||||
}
|
||||
|
||||
const color = assignVectorLayerColor(layer.id)
|
||||
const layers = []
|
||||
|
||||
if(layer.type === "fill" || layer.type === 'fill-extrusion') {
|
||||
return changeFilter(polygonLayer(layer.source, layer['source-layer'], color, Color(color).alpha(0.2).string()))
|
||||
}
|
||||
|
||||
if(layer.type === "symbol" || layer.type === 'circle') {
|
||||
return changeFilter(circleLayer(layer.source, layer['source-layer'], color))
|
||||
}
|
||||
|
||||
if(layer.type === 'line') {
|
||||
return changeFilter(lineLayer(layer.source, layer['source-layer'], color))
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
export function generateColoredLayers(sources) {
|
||||
const styleLayers = []
|
||||
const polyLayers = []
|
||||
const circleLayers = []
|
||||
const lineLayers = []
|
||||
|
||||
Object.keys(sources).forEach(sourceId => {
|
||||
const layers = sources[sourceId]
|
||||
layers.forEach(layerId => {
|
||||
const color = assignVectorLayerColor(layerId)
|
||||
styleLayers.push(circleLayer(sourceId, layerId, color))
|
||||
styleLayers.push(lineLayer(sourceId, layerId, color))
|
||||
styleLayers.push(polygonLayer(sourceId, layerId, color))
|
||||
const color = Color(assignVectorLayerColor(layerId))
|
||||
circleLayers.push(circleLayer(sourceId, layerId, color.alpha(0.3).string()))
|
||||
lineLayers.push(lineLayer(sourceId, layerId, color.alpha(0.3).string()))
|
||||
polyLayers.push(polygonLayer(sourceId, layerId, color.alpha(0.2).string(), color.alpha(0.05).string()))
|
||||
})
|
||||
})
|
||||
return styleLayers
|
||||
|
||||
return polyLayers.concat(lineLayers).concat(circleLayers)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user