label a kml file in Google Maps API v3

2019-09-16 11:37发布

问题:

I am trying to figure out how to use Google Maps API v3 to label a kml polyline that was originally created in ArcGIS Desktop. Unfortunately, the examples that I came across thus far either don't seem to apply to kml files, had dead links, or were examples on how to create pop-ups.

If anyone has an example of how to create labels (not popups) from a kml file let me know.

Side questions:

*In ArcGIS I can use Layer->Properties->HTML Popup to configure the popup for kml. What do I need to do in ArcGIS to specify what attribute I want to use as my label?

*Can I make labels appear only at certain resolutions?

回答1:

You can't add labels using the Google Maps Javascript API KmlLayer, if your KML isn't too complicated, you can use a third party parser (like geoxml3 or geoxml-v3) to render your KML as native Google Maps Javascript API v3 Polylines, and add labels to those.

labeling options:

  • polyline with label in javascript
  • MapLabel
  • InfoBox