Skip to content

Commit d35de35

Browse files
committed
Compatibility with Google Earth and Organic maps
1 parent b03b914 commit d35de35

1 file changed

Lines changed: 38 additions & 6 deletions

File tree

src/index.js

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -390,16 +390,29 @@ function toKML (routeData, progress) {
390390
}).join('\n ')
391391

392392
if (!routeData.pois || routeData.pois.length === 0) {
393-
// Ensure that there is at least one other <Placemark> apart from route for maps.me app
393+
// Ensure that there is at least one other <Placemark>
394394
poiXML += `<Placemark>
395-
<name>${escapeXML(routeData.routeName)} End</name>
395+
<name>${escapeXML(routeData.routeName)} Start</name>
396+
<styleUrl>#placemark-bluegray</styleUrl>
397+
<description>Beginning of route '${escapeXML(routeData.routeName)}'</description>
398+
<Point>
399+
<coordinates>${routeData.vertices[0].slice().reverse().join(',')}</coordinates>
400+
</Point>
401+
</Placemark>
402+
<Placemark>
403+
<name>${escapeXML(routeData.routeName)} Destination</name>
404+
<styleUrl>#placemark-green</styleUrl>
396405
<description>End of route '${escapeXML(routeData.routeName)}'</description>
397406
<Point>
398407
<coordinates>${routeData.vertices[routeData.vertices.length - 1].slice().reverse().join(',')}</coordinates>
399408
</Point>
400409
</Placemark>`
401410
}
402411

412+
let altitudeMode = ''
413+
if (routeData.vertices[0].length > 2) {
414+
altitudeMode = '\n <altitudeMode>absolute</altitudeMode>'
415+
}
403416
const coordinates = routeData.vertices.map(p => p.reverse().join(',')).join('\n')
404417
const temp = `<?xml version="1.0" encoding="UTF-8"?>
405418
<kml xmlns="http://www.opengis.net/kml/2.2">
@@ -418,14 +431,33 @@ ${escapeXML(metablock(routeData))}
418431
<color>7f00ff00</color>
419432
</PolyStyle>
420433
</Style>
434+
<Style id="placemark-bluegray">
435+
<IconStyle>
436+
<color>ffd08050</color>
437+
<Icon>
438+
<href>https://omaps.app/placemarks/placemark-bluegray.png</href>
439+
</Icon>
440+
</IconStyle>
441+
<LabelStyle>
442+
<color>ffd08050</color>
443+
</LabelStyle>
444+
</Style>
445+
<Style id="placemark-green">
446+
<IconStyle>
447+
<color>ff00ff00</color>
448+
<Icon>
449+
<href>https://omaps.app/placemarks/placemark-green.png</href>
450+
</Icon>
451+
</IconStyle>
452+
<LabelStyle>
453+
<color>ff00ff00</color>
454+
</LabelStyle>
455+
</Style>
421456
<Placemark>
422457
<name>${escapeXML(routeData.routeName)}</name>
423458
<description>${escapeXML(routeData.routeDesc)}</description>
424459
<styleUrl>#myStyle</styleUrl>
425-
<LineString>
426-
<extrude>1</extrude>
427-
<tessellate>1</tessellate>
428-
<altitudeMode>absolute</altitudeMode>
460+
<LineString>${altitudeMode}
429461
<coordinates>${coordinates}
430462
</coordinates>
431463
</LineString>

0 commit comments

Comments
 (0)