0

I have created a map using the cloudmade and leaflet plugins. I have my markers set and my aim is to create my own control panel with 3 links of places. When you click on a link (eg London) it will pan to the stored lat long of london and the same for the other two. The code i have loads the map but the container disappears and i get the following error message in the console: "Mycontrol.appendhild(link);- Mycontrol is not defined. This still does not work when it is defined.

1) Am i on the right route with this? 2) Any help to get this working on examples or tutorials would be great

Thanks.

Here is the snippet of the code

[CODE]

[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);

[/CODE]

Shimsham84
  • 227
  • 2
  • 12
  • 29

1 Answers1

0

You are trying to extend the Control class, but assigning the result to a var. A new class is not a var, but a function, so remove the var keyword at the start.

Take a look at the source of the leaflet zoom control for an example how to go about it.

flup
  • 26,937
  • 7
  • 52
  • 74