在Google地图的不同图层上显示标记集 [英] Showing sets of markers on different layers of Google map

查看:98
本文介绍了在Google地图的不同图层上显示标记集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在Google地图上显示一组标记. 我知道可以直接在Google地图上添加标记,但是鉴于我有3套标记,一套用于商店,一套用于公园,另一套用于酒店,我如何在3个不同的图层上显示它们,以便以后使用javascript ,我可以通过执行以下操作来隐藏一组标记:

I need to show a set of markers on a Google map. I know markers can be added directly on a Google map but given that I have 3 sets of markers, one for shops, one for parks and another one for hotels, how can I show them on 3 different layers and so that later on using javascript, I be able to hide one set of markers by doing sort of:

myLayer2.setMap(null);

我已经检查了Panoramio图层,但需要先将图像上传到 panoramio ,但对于我来说,某些特定的安全原因,我无法将其上传到Panoramio.我将在本地使用图像,并根据某些条件在运行时设置图像.

I have checked Panoramio layer but it needs the images first to be uploaded to panoramio, but in my case for some particular security reason I cannot upload them to panoramio. I will have images locally and set those at runtime based upon some criteria.

是否可以使用不使用Panoramio方法的方式来进行基于图层的工作?

Is there some way to do layer based work without using panoramio approach?

推荐答案

Maps-API不支持这种自定义图层(您可能从其他map-API(例如,传单)中知道了这些图层).

The Maps-API doesn't support this kind of custom layers(as you maybe know them from other map-API's like e.g. leaflet).

但是要实现类似的功能并不难.

But it's not hard to achieve a similar feature.

您可以使用google.maps.MVCObject.为每个层"为此MVCObject创建一个属性,并将该属性的值设置为null或google.maps.Map-instance( 取决于所需的层"初始状态)

You may use a google.maps.MVCObject. for every "layer" create a property for this MVCObject and set the value of this property to null or the google.maps.Map-instance( depending on the desired initial state of the "layer")

var myLayers=new google.maps.MVCObject();
    myLayers.setValues({parks:null,shops:null,hotels:map});
    //hotels initially are visible

要添加叠加层时...标记到图层"上,将该Overlay的地图属性绑定到MVCObject的相关属​​性:

When you want to add a Overlay...e.g. a Marker, to a "layer", bind the map-property of that Overlay to the related property of the MVCObject:

   parkMarker=new google.maps.Marker({/*options*/});
   parkMarker.bindTo('map',myLayers,'parks');

要切换图层"中所有要素的显示,只需设置MVCObject的属性:

To toggle the display of all features within that "layer" you only need to set the property of the MVCObject:

//show the parks
myLayers.set('parks',map);
//hide the hotels
myLayers.set('hotels',null);

演示:> http://jsfiddle.net/doktormolle/UA85N/

Demo: http://jsfiddle.net/doktormolle/UA85N/

这篇关于在Google地图的不同图层上显示标记集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆