开发者

google maps polygon clickable and zooming

开发者 https://www.devze.com 2023-03-20 05:48 出处:网络
i want to create a clickable polygon on google maps , and after clicking only that polygon will be highlighted. it follows a top down heirarchy rite from selecting a state then county then township an

i want to create a clickable polygon on google maps , and after clicking only that polygon will be highlighted. it follows a top down heirarchy rite from selecting a state then county then township and last section. i only have shp file with township information for different counties. i w开发者_如何学运维as able to convert the shp files to kml and imported them to google maps but is not editable. also i am not able to extract any info from the polygons created from the kml so that i could use the lat, lon pairs for further drilling down


Onclick event for KML overlays only passes the properties from KmlFeatureData section of your KML. So if you want to get any parameters from KML you need to put them in that section. Polygon points are not accessible! The click event returns the following JSON struct that is accessible from your code as well as position which is usually the center for the polygon/feature:

{
  author: {
    email: "nobody@google.com",
    name: "Mr Nobody",
    uri: "http://example.com"
  },
  description: "description",
  id: "id",
  infoWindowHtml: "html",
  name: "name",
  snippet: "snippet"
}

see http://code.google.com/apis/maps/documentation/javascript/overlays.html#KMLLayers for more details.

You could use one of these fields as the name of your lower level KMLs for drill down.

Alternatively you can read in the KML as XML file and read and process its contents client side and draw your polygons from data obtained that way.... This approach is ok as long as your polygons are not detailed.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号