diff options
author | Matthew Somerville <matthew@fury.ukcod.org.uk> | 2011-02-16 20:34:30 +0000 |
---|---|---|
committer | Matthew Somerville <matthew@fury.ukcod.org.uk> | 2011-02-16 20:34:30 +0000 |
commit | 7698b15bf64daee5f8b5a1080984dd1331615032 (patch) | |
tree | 4a44c578f4fd6025fb81af19e23cae675304eb29 /web/js/map-OpenStreetMap.js | |
parent | 7795e8884f7ca313e44aec7983d511a21a3ee524 (diff) |
Map clicking.
Diffstat (limited to 'web/js/map-OpenStreetMap.js')
-rw-r--r-- | web/js/map-OpenStreetMap.js | 46 |
1 files changed, 42 insertions, 4 deletions
diff --git a/web/js/map-OpenStreetMap.js b/web/js/map-OpenStreetMap.js index 1eae62a9a..2c459392e 100644 --- a/web/js/map-OpenStreetMap.js +++ b/web/js/map-OpenStreetMap.js @@ -1,5 +1,5 @@ YAHOO.util.Event.onContentReady('map', function() { - var map = new OpenLayers.Map("map", { + fixmystreet.map = new OpenLayers.Map("map", { controls: [ new OpenLayers.Control.ArgParser(), //new OpenLayers.Control.LayerSwitcher(), @@ -12,16 +12,54 @@ YAHOO.util.Event.onContentReady('map', function() { zoomOffset: 14, numZoomLevels: 4 }); - map.addLayer(osm); + fixmystreet.map.addLayer(osm); var centre = new OpenLayers.LonLat( fixmystreet.longitude, fixmystreet.latitude ); centre.transform( new OpenLayers.Projection("EPSG:4326"), - map.getProjectionObject() + fixmystreet.map.getProjectionObject() ); - map.setCenter(centre, 2); + fixmystreet.map.setCenter(centre, 2); + + var click = new OpenLayers.Control.Click(); + fixmystreet.map.addControl(click); + click.activate(); }); +OpenLayers.Control.Click = OpenLayers.Class(OpenLayers.Control, { + defaultHandlerOptions: { + 'single': true, + 'double': false, + 'pixelTolerance': 0, + 'stopSingle': false, + 'stopDouble': false + }, + + initialize: function(options) { + this.handlerOptions = OpenLayers.Util.extend( + {}, this.defaultHandlerOptions + ); + OpenLayers.Control.prototype.initialize.apply( + this, arguments + ); + this.handler = new OpenLayers.Handler.Click( + this, { + 'click': this.trigger + }, this.handlerOptions + ); + }, + + trigger: function(e) { + var lonlat = fixmystreet.map.getLonLatFromViewPortPx(e.xy); + lonlat.transform( + fixmystreet.map.getProjectionObject(), + new OpenLayers.Projection("EPSG:4326") + ); + document.getElementById('fixmystreet.latitude').value = lonlat.lat; + document.getElementById('fixmystreet.longitude').value = lonlat.lon; + document.getElementById('mapForm').submit(); + } +}); // http://www.openstreetmap.org/openlayers/OpenStreetMap.js (added maxResolution) |