From be2c88b7afd3d2bfb64d18ca8fd32aedc46c049b Mon Sep 17 00:00:00 2001 From: Sanj Date: Sun, 28 Aug 2011 05:24:13 +0530 Subject: [PATCH] JS to display FeatureCollection on map and render list (not tested) --- gazetteer/static/js/gazetteer.js | 25 +++++++++++++++++++++---- gazetteer/templates/search_related.html | 0 2 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 gazetteer/templates/search_related.html diff --git a/gazetteer/static/js/gazetteer.js b/gazetteer/static/js/gazetteer.js index c1f78f2..1271f29 100644 --- a/gazetteer/static/js/gazetteer.js +++ b/gazetteer/static/js/gazetteer.js @@ -1,7 +1,10 @@ $(function() { map = new OpenLayers.Map('map', {}); var baseLayer = new OpenLayers.Layer.OSM( "Openstreetmap Base Layer"); - map.addLayer(baseLayer); +// map.addLayer(baseLayer); + var geojson_format = new OpenLayers.Format.GeoJSON(); + var jsonLayer = new OpenLayers.Layer.Vector(); + map.addLayers([baseLayer, jsonLayer]); var center = new OpenLayers.LonLat(-95, 37.5).transform( new OpenLayers.Projection("EPSG:4326"), map.getProjectionObject() @@ -16,10 +19,24 @@ $(function() { $.getJSON("search_json", { 'bbox': bbox, 'search': search_term - }, function(response) { - console.log(response); + }, function(features) { + $('#mapList').empty(); +// console.log(response); + var currFeatures = jsonLayer.features; + jsonLayer.removeFeatures(currFeatures); + jsonLayer.addFeatures(geojson_format.read(features)); + for (var i=0; i').addClass("mapListItem").attr("data-id", props.id); + var $a = $('').attr("target", "_blank").attr("href", "/admin/places/feature/" + props.id).text(props.preferred_name).appendTo($li); + return $li; +} diff --git a/gazetteer/templates/search_related.html b/gazetteer/templates/search_related.html new file mode 100644 index 0000000..e69de29