85 lines
3.1 KiB
JavaScript
85 lines
3.1 KiB
JavaScript
$(function() {
|
|
$('.mapListSection').css({'opacity': 0});
|
|
map = new OpenLayers.Map('map', {});
|
|
var baseLayer = new OpenLayers.Layer.OSM( "Openstreetmap Base Layer");
|
|
// 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()
|
|
);
|
|
map.setCenter(center, 4);
|
|
|
|
|
|
$('#searchForm').submit(function(e) {
|
|
if ($('.mapListSection').css("opacity") == '0') {
|
|
$('.mapListSection').animate({'opacity': '1'}, 500);
|
|
}
|
|
e.preventDefault();
|
|
var bbox = map.getExtent().toBBOX();
|
|
var search_term = $('#searchField').val();
|
|
$('#searchField').addClass("loading");
|
|
$('#searchTerm').text(search_term);
|
|
$('#searchField').attr("disabled", "disabled");
|
|
$('#mapList tbody').empty();
|
|
$.getJSON("/feature/search.json", {
|
|
'bbox': bbox,
|
|
'q': search_term,
|
|
'srid': 3785,
|
|
'threshold': 0.5,
|
|
'count': 20
|
|
}, function(features) {
|
|
|
|
if (features.hasOwnProperty("error") && features.error != '') {
|
|
alert(features.error);
|
|
return;
|
|
}
|
|
|
|
$('#noOfResults').text(features.results);
|
|
$('#currPageNo').text(features.current_page);
|
|
$('#totalPages').text(features.pages);
|
|
$('#searchField').removeAttr("disabled");
|
|
$('#searchField').removeClass("loading");
|
|
|
|
// var headerRow = getHeaderRow();
|
|
// 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 = getRow(props);
|
|
$('#mapList tbody').append(listItem);
|
|
}
|
|
});
|
|
});
|
|
});
|
|
|
|
function getRow(props) {
|
|
var $tr = $('<tr />');
|
|
var $one = $('<td />').appendTo($tr);
|
|
var $a = $('<a />').attr("href", "/admin/places/feature/" + props.id).text(props.preferred_name).appendTo($one);
|
|
// var $a2 = $('<a />').addClass("viewSimilar").attr("target", "_blank").attr("href", "/search_related?id=" + props.id).text("view similar").appendTo($one);
|
|
$('<td />').text(props.feature_type).appendTo($tr);
|
|
$('<td />').text(props.admin2).appendTo($tr);
|
|
$('<td />').text(props.admin1).appendTo($tr);
|
|
return $tr;
|
|
}
|
|
|
|
|
|
/*
|
|
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;
|
|
}
|
|
|
|
|
|
function getHeaderRow() {
|
|
var heads = ['Preferred Name', 'Feature Type', 'State', 'County']
|
|
var $thead = $('<thead />');
|
|
}
|
|
*/
|