diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2017-10-01 12:08:13 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2017-10-01 12:08:13 +0200 |
commit | a2e517d1a8d373fe997c22a4e1fdd764f6f54208 (patch) | |
tree | 81b370d68994326e07c4ea06d7f8b58e9e093750 | |
parent | 924b77a50fa5cef3ce50c635455ee2a23f8d1289 (diff) | |
download | Chimère-a2e517d1a8d373fe997c22a4e1fdd764f6f54208.tar.bz2 Chimère-a2e517d1a8d373fe997c22a4e1fdd764f6f54208.zip |
Manage display of route and polygon search results on the map
-rw-r--r-- | chimere/static/chimere/js/jquery.chimere.js | 62 | ||||
-rw-r--r-- | chimere/templates/search/search_js.html | 12 |
2 files changed, 31 insertions, 43 deletions
diff --git a/chimere/static/chimere/js/jquery.chimere.js b/chimere/static/chimere/js/jquery.chimere.js index 92c149d..71228a8 100644 --- a/chimere/static/chimere/js/jquery.chimere.js +++ b/chimere/static/chimere/js/jquery.chimere.js @@ -1631,11 +1631,11 @@ function transformCoordToLonLat(coord) { if (feature.geometry.type == 'Point'){ var iconFeature = methods._addMarker(map_id, feature); } else if (feature.geometry.type == 'Polygon') { - methods.addPolygon(map_id, feature); + methods._addPolygon(map_id, feature); } else if (feature.geometry.type == 'MultiPolygon') { - methods.addPolygon(map_id, feature); + methods._addPolygon(map_id, feature); } else if (feature.geometry.type == 'LineString') { - methods.addRoute(map_id, feature); + methods._addRoute(map_id, feature); } else if (feature.geometry.type == 'MultiLineString') { //OL3 methods.addMultiLine(feature); } @@ -2297,7 +2297,7 @@ function transformCoordToLonLat(coord) { */ }, // Put a route on the map - addRoute: function(map_id, feature) { + _addRoute: function(map_id, feature) { var feat = new ol.format.GeoJSON().readFeatures(feature)[0]; feat.setGeometry(transform(feat.getGeometry())); feat.setStyle(new ol.style.Style({ @@ -2307,31 +2307,14 @@ function transformCoordToLonLat(coord) { })); settings[map_id].dbFeatures.push(feat); return; - /* - var polyline = route.geometry; - var point_array = new Array(); - for (i=0; i<polyline.coordinates.length; i++){ - var point = new OpenLayers.Geometry.Point(polyline.coordinates[i][0], - polyline.coordinates[i][1]); - point_array.push(point); - } - var linestring = new OpenLayers.Geometry.LineString(point_array); - linestring.transform(EPSG_DISPLAY_PROJECTION, settings[map_id].map.getProjectionObject()); - settings[map_id].current_feature = new OpenLayers.Feature.Vector(); - - var style = OpenLayers.Util.extend({}, - OpenLayers.Feature.Vector.style['default']); - style.strokeColor = route.properties.color; - style.strokeWidth = 3; - settings[map_id].current_feature.style = style; - settings[map_id].current_feature.geometry = linestring; - settings[map_id].layerVectors.addFeatures([settings[map_id].current_feature]); - if (settings[map_id].display_route && settings[map_id].display_route == route.properties.pk){ - var dataExtent = settings[map_id].current_feature.geometry.getBounds(); - map.zoomToExtent(dataExtent, closest=true); - methods.loadCategories(); + }, + addRoute: function(feature) { + var map_id = methods.map_id(this); + if (!map_id){ + alert("addRoute - Public method only"); + return; } - */ + return methods._addRoute(map_id, feature); }, /* * Put a multiline on the map @@ -2350,7 +2333,7 @@ function transformCoordToLonLat(coord) { settings[map_id].layerVectors.addFeatures(feats); }, // Put a polygon on the map - addPolygon: function(map_id, feature) { + _addPolygon: function(map_id, feature) { var feat = new ol.format.GeoJSON().readFeatures(feature)[0]; feat.setGeometry(transform(feat.getGeometry())); feat.setStyle(new ol.style.Style({ @@ -2361,19 +2344,14 @@ function transformCoordToLonLat(coord) { })); settings[map_id].dbFeatures.push(feat); return; - /* - var gformat = new OpenLayers.Format.GeoJSON(); - var feats = gformat.read(feature); - var style = OpenLayers.Util.extend({}, - OpenLayers.Feature.Vector.style['default']); - style.strokeColor = feature.properties.color; - style.strokeWidth = 2; - feats[0].style = style; - feats[0].geometry = feats[0].geometry.transform( - EPSG_DISPLAY_PROJECTION, - settings[map_id].map.getProjectionObject()); - settings[map_id].layerVectors.addFeatures(feats); - */ + }, + addPolygon: function(feature) { + var map_id = methods.map_id(this); + if (!map_id){ + alert("addPolygon - Public method only"); + return; + } + return methods._addPolygon(map_id, feature); }, routingInputChange: function(nominatim_id){ $('#map_menu_clear').show(); diff --git a/chimere/templates/search/search_js.html b/chimere/templates/search/search_js.html index 44a7ee9..814a3f4 100644 --- a/chimere/templates/search/search_js.html +++ b/chimere/templates/search/search_js.html @@ -15,7 +15,17 @@ $(function(){ var c_idx = geo_objects[idx].properties.pk; if (search_result.indexOf(c_idx) == -1){ search_result.push(c_idx); - geo_features[c_idx] = $('#main-map').chimere('addMarker', + var geom_type = geo_objects[idx].geometry.type; + if (geom_type == 'Point'){ + action = 'addMarker'; + } else if (geom_type == 'LineString'){ + action = 'addRoute'; + } else if (geom_type == 'Polygon' || geom_type == 'MultiPolygon'){ + action = 'addPolygon'; + } else { + continue + } + geo_features[c_idx] = $('#main-map').chimere(action, geo_objects[idx]); } } |