x

Anzeige eines vordefinierten Kartenabschnittes mittels OpenLayers


  1. Anzeige eines vordefinierten Kartenabschnittes mittels OpenLayers · aquacoach (Gast) · 02.10.2010 15:26 · [flux]

    Hallo,

    Suchen im Forum und Testen haben leider nicht den Erfolg gebracht.

    Ich möchte die Anzeige gerne auf einen bestimmten Kartenabschnitt begrenzen, in meinem Fall auf Indonesien.

    Ich habe die Position TopLeft und BottomRight bestimmt:

    TopLeft:
    http://www.openstreetmap.org/?lat=8.3&l … &mlon=92.9
    http://tools.geofabrik.de/map/?type=Geo … m=7&grid=1

    BottomRight
    http://www.openstreetmap.org/?lat=-13.8 … mlon=143.4
    http://tools.geofabrik.de/map/?type=Geo … m=7&grid=1

    Laut http://dev.openlayers.org/docs/files/Op … ers.Bounds sind
    also meine Bounds 92.9, -13.8, 143.4, 8.3.

    Folgender Code funktioniert leider noch nicht vollständig. Indonesien wird angezeigt, aber ich kann aus der Karte rauszoomen und sehe auch Teile der Karte die ich ja nicht anzeigen wollte.

    <html␣xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>Test:␣OSM␣Web␣nur␣Indonesien</title>
    
    <link␣rel="stylesheet"␣href="../theme/default/style.css"␣type="text/css"␣/>
    <link␣rel="stylesheet"␣href="style.css"␣type="text/css"␣/>
    
    <script␣src="../lib/OpenLayers.js"></script>
    <script␣type="text/javascript">
    //␣making␣this␣a␣global␣variable␣so␣that␣it␣is␣accessible␣for␣debugging/inspecting␣in␣Firebug
    var␣map␣=␣null;
    
    function␣init()␣{
    extent␣=␣new␣OpenLayers.Bounds(92.9,␣-13.8,␣143.4,␣8.3);
    
    var␣leftBottom␣=␣new␣OpenLayers.LonLat(92.9,␣-13.8).transform(
    new␣OpenLayers.Projection("EPSG:4326"),
    new␣OpenLayers.Projection("EPSG:900913")
    );
    var␣rightTop␣=␣new␣OpenLayers.LonLat(143.4,␣8.3).transform(
    new␣OpenLayers.Projection("EPSG:4326"),
    new␣OpenLayers.Projection("EPSG:900913")
    );
    extent␣=␣new␣OpenLayers.Bounds(leftBottom.lon,␣leftBottom.lat,␣rightTop.lon,␣rightTop.lat);
    
    map␣=␣new␣OpenLayers.Map('map',␣{
    projection:␣new␣OpenLayers.Projection("EPSG:4326"),
    displayProjection:␣new␣OpenLayers.Projection("EPSG:4326"),
    //maxExtent:␣new␣OpenLayers.Bounds(-180,-90,180,90),
    maxExtent:␣extent,
    restrictedExtent:␣extent,
    //minScale:␣3,
    //maxScale:␣10,
    //maxResolution:␣0.3515625,
    //units:␣'degrees'
    });
    
    var␣layer_osm␣=␣new␣OpenLayers.Layer.OSM("Test",␣"http://tile.openstreetmap.org/${z}/${x}/${y}.png",␣{
    numZoomLevels:␣16
    });
    map.addLayer(layer_osm);
    
    map.addControl(new␣OpenLayers.Control.ScaleLine());
    map.addControl(new␣OpenLayers.Control.PanZoomBar());
    
    map.zoomToMaxExtent();
    //map.zoomTo(5);
    }
    
    </script>
    </head>
    <body␣onload="init()">
    <div␣id="map"␣class="smallmap"></div>
    </body>
    </html>
    

    Was mache ich verkehrt?

    Coach