JS to display FeatureCollection on map and render list (not tested)

This commit is contained in:
Sanj 2011-08-28 05:24:13 +05:30
parent 3a5253aaab
commit be2c88b7af
2 changed files with 21 additions and 4 deletions

View File

@ -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<features.features.length;i++) {
var f = features.features[i];
var props = f.properties;
var listItem = getLi(props);
$('#mapList').append(listItem);
}
});
});
});
function getLi(props) {
var $li = $('<li />').addClass("mapListItem").attr("data-id", props.id);
var $a = $('<a />').attr("target", "_blank").attr("href", "/admin/places/feature/" + props.id).text(props.preferred_name).appendTo($li);
return $li;
}

View File