Leaflet und LayerSwitch

Hallo,
ich versuche gerade eine Karte auf Basis von Leaflet zu erstellen. Die Anzeige der Layer funktioniert auch soweit, nur den LayerSwitch bekomm ich einfach nicht zum laufen. Wobei ich mich egtl. an das Example gehalten habe.

Hat einer von euch das schonmal hinbekomen und kann mir behilflich sein?

DEr peinliche Fehler ist nun auch hier behoben.


<!DOCTYPE html>
<html>
<head>
    <title>Leaflet Layers Control Example</title>
    <meta charset="utf-8" />

    <link rel="stylesheet" href="leaflet/leaflet.css" />
    <!--[if lte IE 8]><link rel="stylesheet" href="leaflet/leaflet.ie.css" /><![endif]-->
    <style>
        body {
            padding: 0;
            margin: 0;
        }
        html, body, #map {
            height: 100%;
        }
</style>
<script src="leaflet/leaflet.js"></script>
</head>
<body>
    <div id="map"></div>

    <script>
        var mapquest_osm = new L.TileLayer("http://{s}.mqcdn.com/tiles/1.0.0/osm/{z}/{x}/{y}.png", {maxZoom: 14, minZoom: 1, attribution: 'Data, imagery and map information provided by <a href="http://open.mapquest.co.uk" target="_blank">MapQuest</a>, <a href="http://www.openstreetmap.org/" target="_blank">OpenStreetMap</a> and contributors, <a href=\"http://creativecommons.org/licenses/by-sa/2.0/\" target=\"_blank\">CC-BY-SA</a>', subdomains: ["otile1","otile2","otile3","otile4"]});
        var mapnik_osm = new L.TileLayer("http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", {maxZoom: 14, minZoom: 1, attribution: "Map: &copy; 2012 <a href=\"http://www.openstreetmap.org\" target=\"_blank\" style=\"\">OpenStreetMap contributors</a>, <a href=\"http://creativecommons.org/licenses/by-sa/2.0/\" target=\"_blank\">CC-BY-SA</a>"});
        var radreise_wiki = new L.TileLayer("http://localhost/radreise-wiki/{z}/{x}/{y}.png", {maxZoom: 14, minZoom: 1});

        var map = new L.Map('map', {center: new L.LatLng(50, 2), zoom: 5, layers: [mapquest_osm, radreise_wiki]});

        map.addControl(new L.Control.Layers({"MapQuest Open":mapquest_osm, "Mapnik":mapnik_osm}, {"RadReise-Wiki":radreise_wiki}));
    </script>
</body>
</html>

Hmm, wenn ich mir das Layer-Example eins-zu-eins nach lokal kopiere, sehe ich nur die Marker und
weder Karten noch Layer-Control.

Edit: Lesen müsste man können, funktioniert nur mit der Latest, also: richtige Version runterladen… :wink:

Ja ich nutze das latest. Mein Problem ist, dass ich nicht weiß, wo der Fehler in meinem Code liegt.

osm_mapnik vs. mapnik_osm

Du solltest Dir unbedingt Firebug für den Firefox installieren. Ohne ein vernünftiges Debugging Tool kann man eigentlich überhaupt nicht sinnvoll mit Javascript arbeiten.

in der Konsole würdest du dann die Fehlermeldung zu deinem Code sehen:


mapnik_osm is not defined

"Mapnik": mapnik_osm

hüst Wie peinlich…