06308: Improved OpenStreetMap support – LimeSurvey bugs and feature requests

The Javascript function OSMapInitialize() has been heavily modified to create a draggable marker and be able to set it also with right click, and OSM has been added as good value for 'Use mapping service' option. From e7d286b41731446ba9d600555112c2a22f5c09c0 Mon Sep 17 00:00:00 2001 From: Roberto Guido <,roberto.guido@linux.it>, Date: Sun, 8 Jul 2012 16:06:14 -0400 Subject: [PATCH] Improved support for OpenStreetMap, now able to move the marker (with right click also) --- application/helpers/common_helper.php | 3 +- scripts/survey_runtime.js | 88 +++++++++++++++++++++++++++----- 2 files changed, 76 insertions(+), 15 deletions(-) diff --git a/application/helpers/common_helper.php b/application/helpers/common_helper.php index a999def..7d10558 100644 --- a/application/helpers/common_helper.php +++ b/application/helpers/common_helper.php @@ -3358,7 +3358,8 @@ function questionAttributes($returnByName=false) 'sortorder'=>,90, 'inputtype'=>,'singleselect', 'options'=>,array(0=>,$clang->,gT('Off'), - 1=>,$clang->,gT('Google Maps')), + 1=>,$clang->,gT('Google Maps'), + 2=>,$clang->,gT('OpenStreetMap')), 'default' =>, 0, 'help'=>,$clang->,gT('Activate this to show a map above the input field where the user can select a location'), 'caption'=>,$clang->,gT('Use mapping service')), diff --git a/scripts/survey_runtime.js b/scripts/survey_runtime.js index 67df312..f41f725 100644 --- a/scripts/survey_runtime.js +++ b/scripts/survey_runtime.js @@ -155,23 +155,83 @@ gmaps = new Object, osmaps = new Object, zoom = [], -// OSMap functions function OSMapInitialize(question,lat,lng){ + var name = question.substr(0,question.length - 2), + + var map = new OpenLayers.Map('gmap_canvas_' + question), + map.addLayer(new OpenLayers.Layer.OSM()), + var lonLat = new OpenLayers.LonLat(lng,lat) + .transform( + new OpenLayers.Projection('EPSG:4326'), // transform from WGS 1984 + map.getProjectionObject() // to Spherical Mercator Projection + ), + + var renderer = OpenLayers.Util.getParameters(window.location.href).renderer, + renderer = (renderer) ? [renderer] : OpenLayers.Layer.Vector.prototype.renderers, + + var vectorLayer = new OpenLayers.Layer.Vector('Simple Geometry', { + renderers: renderer + }), + + var style_mark = OpenLayers.Util.extend({}, OpenLayers.Feature.Vector.style['default']), + var point = new OpenLayers.Geometry.Point(lonLat.lon, lonLat.lat), + var pointFeature = new OpenLayers.Feature.Vector(point,null,style_mark), + vectorLayer.addFeatures([pointFeature]), - map = new OpenLayers.Map('gmap_canvas_' + question), - map.addLayer(new OpenLayers.Layer.OSM()), - var lonLat = new OpenLayers.LonLat(lat,lng) - .transform( - new OpenLayers.Projection('EPSG:4326'), // transform from WGS 1984 - map.getProjectionObject() // to Spherical Mercator Projection - ), - var zoom=11, - var markers = new OpenLayers.Layer.Markers( 'Markers' ), - map.addLayer(markers), - markers.addMarker(new OpenLayers.Marker(lonLat)), - map.setCenter (lonLat, zoom), - return map, + map.div.oncontextmenu = function noContextMenu(e) { + return false, + }, + + OpenLayers.Control.Click = OpenLayers.Class(OpenLayers.Control, { + defaultHandlerOptions: { + 'single': true, + 'double': false, + 'pixelTolerance': 0, + 'stopSingle': false, + 'stopDouble': false + }, + + handleRightClicks:true, + + initialize: function(options) { + this.handlerOptions = OpenLayers.Util.extend({}, this.defaultHandlerOptions), + OpenLayers.Control.prototype.initialize.apply (this, arguments), + this.handler = new OpenLayers.Handler.Click( + this, { + 'rightclick': this.onRightClick + }, this.handlerOptions + ), + }, + + onRightClick: function clicked (e){ + var lonlat = new OpenLayers.LonLat(1, 1), + lonlat = map.getLonLatFromViewPortPx (e.xy), + pointFeature.move (lonlat), + var point = new OpenLayers.Geometry.Point(pointFeature.geometry.x, pointFeature.geometry.y), + point.transform(map.getProjectionObject(), new OpenLayers.Projection('EPSG:4326')), + geocodeAddress(name, new google.maps.LatLng(point.y,point.x)), + $('#answer'+question).val(Math.round(point.y*10000)/10000 + ' ' + Math.round(point.x*10000)/10000), + } + }), + + var click = new OpenLayers.Control.Click(), + map.addControl(click), + click.activate(), + + var dragFeature = new OpenLayers.Control.DragFeature(vectorLayer, { + onComplete: function(feature){ + var point = new OpenLayers.Geometry.Point(feature.geometry.x, feature.geometry.y), + point.transform(map.getProjectionObject(), new OpenLayers.Projection('EPSG:4326')), + geocodeAddress(name, new google.maps.LatLng(point.y,point.x)), + $('#answer'+question).val(Math.round(point.y*10000)/10000 + ' ' + Math.round(point.x*10000)/10000), + }, + }), + map.addControl(dragFeature), + dragFeature.activate(), + map.addLayer(vectorLayer), + map.setCenter (lonLat, zoom[name]), + return map, } //// Google Maps Functions (for API V3) //// -- 1.7.2.5 Source.


Яндекс.Метрика Рейтинг@Mail.ru Free Web Counter
page counter
Last Modified: April 19, 2016 @ 12:06 am