X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/4da22eee1acaa77e9059baf1eaa71f302d2ba20f..5449cf4adcc1fad4b9f43426e6d3e4a8f65e6fbb:/public/javascripts/map.js diff --git a/public/javascripts/map.js b/public/javascripts/map.js index c2ddf9c39..3cfa2f9a1 100644 --- a/public/javascripts/map.js +++ b/public/javascripts/map.js @@ -1,6 +1,7 @@ var epsg4326 = new OpenLayers.Projection("EPSG:4326"); var map; var markers; +var vectors; var popup; var nonamekeys = { @@ -32,7 +33,8 @@ function createMap(divName, options) { ], units: "m", maxResolution: 156543.0339, - numZoomLevels: 20 + numZoomLevels: 20, + displayProjection: new OpenLayers.Projection("EPSG:4326") }); var mapnik = new OpenLayers.Layer.OSM.Mapnik("Mapnik", { @@ -81,6 +83,17 @@ function createMap(divName, options) { projection: "EPSG:900913" }); map.addLayer(markers); + + vectors = new OpenLayers.Layer.Vector("Vectors", { + displayInLayerSwitcher: false, + numZoomLevels: numZoomLevels, + maxExtent: new OpenLayers.Bounds(-20037508,-20037508,20037508,20037508), + maxResolution: 156543, + units: "m", + projection: "EPSG:900913" + }); + map.addLayer(vectors); + return map; } @@ -105,6 +118,19 @@ function addMarkerToMap(position, icon, description) { return marker; } +function addBoxToMap(boxbounds) { + var geometry = boxbounds.toGeometry().transform(epsg4326, map.getProjectionObject()); + var box = new OpenLayers.Feature.Vector(geometry, {}, { + strokeWidth: 2, + strokeColor: '#ee9900', + fillOpacity: 0, + }); + + vectors.addFeatures(box); + + return box; +} + function openMapPopup(marker, description) { closeMapPopup(); @@ -128,11 +154,18 @@ function removeMarkerFromMap(marker){ markers.removeMarker(marker); } +function removeBoxFromMap(box){ + vectors.removeFeature(box); +} + function getMapCenter(center, zoom) { return map.getCenter().clone().transform(map.getProjectionObject(), epsg4326); } function setMapCenter(center, zoom) { + zoom = parseInt(zoom); + var numzoom = map.getNumZoomLevels(); + if (zoom >= numzoom) zoom = numzoom - 1; map.setCenter(center.clone().transform(epsg4326, map.getProjectionObject()), zoom); } @@ -140,7 +173,7 @@ function setMapExtent(extent) { map.zoomToExtent(extent.clone().transform(epsg4326, map.getProjectionObject())); } -function getMapExtent(extent) { +function getMapExtent() { return map.getExtent().clone().transform(map.getProjectionObject(), epsg4326); }