Leaflet & Clodmade:锚链接到存储的经纬度/经度位置



我使用cloudmade和传单插件创建了一个地图。我已经设置了标记,我的目标是创建自己的控制面板,其中包含 3 个位置链接。当您单击一个链接(例如伦敦)时,它将平移到存储的伦敦经度,其他两个也是如此。我拥有的代码加载了地图,但容器消失了,我在控制台中收到以下错误消息:"Mycontrol.appendhild(link);- Mycontrol未定义。这在定义时仍然不起作用。

1)我走在正确的道路上吗?2)任何帮助使其在示例或教程中工作都会很棒

谢谢。

这是代码片段

[代码]

[Cloudmade API Key and URL]
[Leaflet ICON Properties]
[Leaflet MARKERS]
[Leaflet toggle styles]
//CONTROL
var MyControl = L.Control.extend({
    options: {
        position: 'topright'
    },
    onAdd: function (map, position) {
        // create the control container
        var container = L.DomUtil.create('div', 'my-custom-control');
        // ... initialize other DOM elements, add listeners, etc.
        function createMapLink(location, zoom, name) {
            var link = document.createElement('a');
            link.href = '';
            link.innerHTML = "Go to " + name;
            link.onclick = function() {
                map.setCenter(location, zoom);
                return false;
            }
            Mycontrol.appendChild(link);
        }
        createMapLink(new L.LatLng(lat,lon), 11, 'Location1');
        createMapLink(new L.LatLng(lat,lon), 11, 'Location2');
        createMapLink(new L.LatLng(lat,lon), 11, 'Location3');
        return container;
    }
});
map.addControl(new MyControl());

L.control.layers(baseMaps, overlayMaps, MyControl).addTo(map);

[/代码]

您正在尝试扩展 Control 类,但将结果分配给 var。新类不是 var,而是一个函数,因此请在开头删除 var 关键字。

查看传单缩放控件的来源,以获取有关如何操作的示例。

最新更新