placemark/togeojson

Way to determine icon-offset pixel units

kthyer opened this issue · 4 comments

I have been playing around with both Google Earth and Google My Maps tools and converting the exported KML files to GeoJSON using this tool.

I noticed when importing from these two sources, the icon-offset property that results from converting to GeoJSON gives just the x and y pixels for the feature of the KML files. The following are taken from the KML files.

Google Earth: <hotSpot x="32" y="1" xunits="pixels" yunits="pixels"/>
Google My Maps: <hotSpot x="32" xunits="pixels" y="64" yunits="insetPixels"/>

Google Earth uses yunits="pixels" whereas Google My Maps uses yunits="insetPixels"

What this means when I convert to GeoJSON is that I have no idea what yunit the icon-offset it is based off of. If I attempt to adjust the offset in my map display using this it will be correct for one source, but completely wrong for the other source.

Are there plans or considerations for being able to get this information through the conversion process?

I forked your online tool so that it used the latest version of this library and that is where you can reproduce what I'm seeing by uploading the KML files I have provided in the ZIP file below.

The fork can be found here: https://observablehq.com/d/96ff9e6b1b6edfb1

Google Placemarks.zip

Thank you and let me know if I can help clarify anything.

Reading this there is a pixels, insetPixels and fraction unit types. https://developers.google.com/kml/documentation/kmlreference#hotspot

Would it be possible to add new fields that gives the xunit and yunit type? Or is there another possible way to approach this? I'd be happy to help with a PR, but want to know what you think is best option and in scope for this project.

tmcw commented

Whoops, accidentally closed the wrong issue, sorry.

Definitely, adding, say icon-xscale and icon-yscale attributes seems right. If you're interested in fixing this with a PR, it'd start here:

const left = parseFloat(hotspot.getAttribute("x") || "");
const top = parseFloat(hotspot.getAttribute("y") || "");
if (!isNaN(left) && !isNaN(top)) return { "icon-offset": [left, top] };
return {};

@tmcw I created a PR for this in #78

I opted to go with icon-offset-units in an [x-unit-type, y-unit-type] array format that maps well with the existing icon-offset style property.

Let me know if you would rather it be separated into icon-xscale or icon-yscale like you have in your previous comment and I can update it.

Thanks

tmcw commented

👍 Merged in #79 and released in 5.1.0! Thanks @kthyer