Skip to content

Commit

Permalink
Improve KML Export Styles
Browse files Browse the repository at this point in the history
  • Loading branch information
tariqksoliman committed Nov 14, 2023
1 parent 3fba967 commit 8bd22d0
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 23 deletions.
65 changes: 47 additions & 18 deletions src/essence/Basics/Formulae_/Formulae_.js
Original file line number Diff line number Diff line change
Expand Up @@ -1452,27 +1452,56 @@ var Formulae_ = {
return string
},
// https://github.com/mapbox/simplestyle-spec
geoJSONForceSimpleStyleSpec(geojson, stringifyPropertyObjects) {
geoJSONForceSimpleStyleSpec(
geojson,
stringifyPropertyObjects,
defaultStyle,
useKeyAsName
) {
const defStyle = defaultStyle
? JSON.parse(JSON.stringify(defaultStyle))
: {}

const g = JSON.parse(JSON.stringify(geojson))
g.features.forEach((f) => {
if (f.properties.style) {
// style.color -> stroke
if (f.properties.style.color != null)
f.properties['stroke'] = f.properties.style.color
// style.opacity -> stroke-opacity
if (f.properties.style.opacity != null)
f.properties['stroke-opacity'] = f.properties.style.opacity
// style.weight -> stroke-width
if (f.properties.style.weight != null)
f.properties['stroke-width'] = f.properties.style.weight
// style.fillColor -> fill
if (f.properties.style.fillColor != null)
f.properties['fill'] = f.properties.style.fillColor
// style.fillOpacity -> fill-opacity
if (f.properties.style.fillOpacity != null)
f.properties['fill-opacity'] =
f.properties.style.fillOpacity
let pstyle = f.properties.style || {}

if (useKeyAsName && f.properties[useKeyAsName] != null) {
if (typeof f.properties[useKeyAsName] === 'number')
f.properties[useKeyAsName] = `${f.properties[useKeyAsName]}`
}

if (f.geometry.type.toLowerCase() === 'point') {
if (pstyle.fillColor != null)
f.properties['marker-color'] = pstyle.fillColor
else if (defStyle.fillColor != null)
f.properties['marker-color'] = defStyle.fillColor
}
// style.color -> stroke
if (pstyle.color != null) f.properties['stroke'] = pstyle.color
else if (defStyle.color != null)
f.properties['stroke'] = defStyle.color
// style.opacity -> stroke-opacity
if (pstyle.opacity != null)
f.properties['stroke-opacity'] = pstyle.opacity
if (defStyle.opacity != null)
f.properties['stroke-opacity'] = defStyle.opacity
// style.weight -> stroke-width
if (pstyle.weight != null)
f.properties['stroke-width'] = pstyle.weight
if (defStyle.weight != null)
f.properties['stroke-width'] = defStyle.weight
// style.fillColor -> fill
if (pstyle.fillColor != null)
f.properties['fill'] = pstyle.fillColor
if (defStyle.fillColor != null)
f.properties['fill'] = defStyle.fillColor
// style.fillOpacity -> fill-opacity
if (pstyle.fillOpacity != null)
f.properties['fill-opacity'] = pstyle.fillOpacity
if (defStyle.fillOpacity != null)
f.properties['fill-opacity'] = defStyle.fillOpacity

if (stringifyPropertyObjects)
Object.keys(f.properties).forEach((p) => {
const val = f.properties[p]
Expand Down
13 changes: 8 additions & 5 deletions src/essence/Tools/Layers/LayersTool.js
Original file line number Diff line number Diff line change
Expand Up @@ -796,16 +796,19 @@ function interfaceWithMMGIS(fromInit) {
break
case 'kml':
const kml = tokml(
F_.geoJSONForceSimpleStyleSpec(geojson, true),
F_.geoJSONForceSimpleStyleSpec(
geojson,
true,
L_.layers.data[layerUUID]?.style,
layerData.useKeyAsName
),
{
name: layerData.useKeyAsName || null,
description: 'description',
name: layerData.useKeyAsName || false,
description: 'Generated by MMGIS',
timestamp:
layerData.time?.enabled === true
? layerData.time.endProp || null
: null,
documentName: filename,
documentDescription: 'Generated by MMGIS',
simplestyle: true,
}
)
Expand Down

0 comments on commit 8bd22d0

Please sign in to comment.