使用全局变量的传单iconurl

时间:2014-06-24 04:41:47

标签: leaflet

我试图让我的iconurl成为一个全局变量(或任何变量,称为var1),但它似乎不起作用。代码如下。请注意,当iconurl设置为“http://www.our.server.com/picture”时,代码可以正常工作,但如果我们设置var1 ='http://www.our.server.com/picture'然后执行iconurl:var1(如下所示),则不会。我检查了控制台,var1是正确的(我们也在其他地方成功使用了这个链接/变量)。

var myIconData = L.Icon.Label.extend({
options: {

iconUrl: var1,
shadowUrl: 'images/marker2.png',

iconSize:     [40, 40], // size of the icon
shadowSize:   [50, 55], // size of the shadow
iconAnchor:   [20, 50], // point of the icon which will correspond to marker's location
shadowAnchor: [25, 55],  // the same for the shadow
popupAnchor:  [0, -55], // point from which the popup should open relative to the iconAnchor

labelAnchor: [0, 0],
wrapperAnchor: [20, 50],
labelClassName: 'sweet-deal-label'
}
});

我们如何调用标记(有效):

mymarker=new L.Marker([position.coords.latitude, position.coords.longitude],{ 'icon': new myIconData(), 'title': username });

感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

你的问题必须在其他地方。

您可以使用变量:点击此处http://franceimage.github.io/leaflet/7/

// custom icon
var image = 'leaf-green.png'; 
var greenIcon = L.icon({
    iconUrl: image,
    shadowUrl: 'leaf-shadow.png',

    iconSize:     [38, 95], // size of the icon
    shadowSize:   [50, 64], // size of the shadow
    iconAnchor:   [22, 94], // point of the icon which will correspond to marker's location
    shadowAnchor: [4, 62],  // the same for the shadow
    popupAnchor:  [-3, -76] // point from which the popup should open relative to the iconAnchor
});

我也试过一个http表格(但我不建议)

你遇到问题时检查了你的javascript控制台吗?