OpenLayers - Center und Zoom
Geschrieben von BorderCounter (Gast) am 03. Juni 2022 14:09:03: [flux]
Hallo zusammen,
vielleicht ist dieses Forum nicht die richtige Anlaufstelle? Vielleicht doch? Auf jedem Fall brauche ich Hilfe 🙂
Ich plotte mittels eines relativ einfachen scriptes das auf einem Raspberry PI läuft im Netzwerk zuhause verschiedene GPX-Dateien.
Siehe Script:
␣<div␣id="mapdiv"></div> <script␣src="http://www.openlayers.org/api/OpenLayers.js"></script> <script> map␣=␣new␣OpenLayers.Map("mapdiv"); map.addLayer(new␣OpenLayers.Layer.OSM());
var␣20200414=␣new␣OpenLayers.Layer.Vector("20200414",␣{ strategies:␣[new␣OpenLayers.Strategy.Fixed()], protocol:␣new␣OpenLayers.Protocol.HTTP({ url:␣"../gpx/20200414.gpx", format:␣new␣OpenLayers.Format.GPX() }), style:␣{strokeColor:␣"green",␣strokeWidth:␣5,␣strokeOpacity:␣0.5}, projection:␣new␣OpenLayers.Projection("EPSG:4326") }); map.addLayer(20200414);
var␣20200415=␣new␣OpenLayers.Layer.Vector("20200415",␣{ strategies:␣[new␣OpenLayers.Strategy.Fixed()], protocol:␣new␣OpenLayers.Protocol.HTTP({ url:␣"../gpx/20200415.gpx", format:␣new␣OpenLayers.Format.GPX() }), style:␣{strokeColor:␣"green",␣strokeWidth:␣5,␣strokeOpacity:␣0.5}, projection:␣new␣OpenLayers.Projection("EPSG:4326") }); map.addLayer(20200415);
//␣Weitere␣GPX␣Dateien␣folgend...
//␣create␣layer␣switcher␣widget␣in␣top␣right␣corner␣of␣map. var␣layer_switcher=␣new␣OpenLayers.Control.LayerSwitcher({}); map.addControl(layer_switcher); //Set␣start␣centrepoint␣and␣zoom var␣lonLat␣=␣new␣OpenLayers.LonLat(␣10,␣50␣) .transform( new␣OpenLayers.Projection("EPSG:4326"),␣//␣transform␣from␣WGS␣1984 map.getProjectionObject()␣//␣to␣Spherical␣Mercator␣Projection ); var␣zoom=5; map.setCenter␣(lonLat,␣zoom);
</script>
Über var zoom wird der Zoom eingestellt und via var lonLat der Center der Karte.
Ist es ohne extremen Aufwand irgendwie möglich, die Karte automatisch auf die optimale Stufe zu zoomen, so dass die Tracks der GPX-Dateien vollständig sichtbar sind?
Ich bin leider kein Programmierer und klicke mir das alles nur zusammen. Aus der OpenLayers Doku bin ich nicht wirklich schlau geworden 🙁
Antworten:
-
Re: OpenLayers - Center und Zoom
·
maxbe (Gast)
·
03.06.2022 15:23
[flux]
-
Re: OpenLayers - Center und Zoom
·
lonvia (Gast)
·
03.06.2022 15:51
[flux]
-
Re: OpenLayers - Center und Zoom
·
BorderCounter (Gast)
·
07.06.2022 15:11
[flux]
-
Re: OpenLayers - Center und Zoom
·
maxbe (Gast)
·
08.06.2022 13:13
[flux]
-
Re: OpenLayers - Center und Zoom
·
ikonor (Gast)
·
11.06.2022 10:26
[flux]
-
Re: OpenLayers - Center und Zoom
·
AlterSachse (Gast)
·
13.06.2022 07:15
[flux]