first stab at highlighting map behaviour

This commit is contained in:
Sanj 2011-09-01 02:50:46 +05:30
parent cce48f4a18
commit ebd26490e6

View File

@ -5,41 +5,31 @@ $(function() {
// 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);
$('.first').click(function() {
$('#page_no').val('1');
$('#searchForm').submit();
var mapControl = new OpenLayers.Control.SelectFeature(jsonLayer, {hover: true});
map.addControl(mapControl);
mapControl.activate();
jsonLayer.events.on({
'featureselected': onFeatureSelect,
'featureunselected': onFeatureUnselect
});
$('.last').click(function() {
var lastPage = parseInt($('#totalPages').text());
$('#page_no').val(lastPage);
$('#searchForm').submit();
});
$('.next').click(function() {
var currPage = parseInt($('#page_no').val());
var lastPage = parseInt($('#totalPages').text());
if (currPage < lastPage) {
$('#page_no').val(currPage + 1);
$('#searchForm').submit();
function getFeatureById(id) {
var features = jsonLayer.features;
for (var i=0; i < features.length; i++) {
if (features[i].attributes.id == id) {
return features[i];
}
});
$('.previous').click(function() {
var currPage = parseInt($('#page_no').val());
if (currPage > 1) {
$('#page_no').val(currPage - 1);
$('#searchForm').submit();
}
});
return false;
}
$('#searchForm').submit(function(e) {
e.preventDefault();
@ -83,10 +73,47 @@ $(function() {
}
});
});
/* pagination code */
$('.first').click(function() {
$('#page_no').val('1');
$('#searchForm').submit();
});
$('.last').click(function() {
var lastPage = parseInt($('#totalPages').text());
$('#page_no').val(lastPage);
$('#searchForm').submit();
});
$('.next').click(function() {
var currPage = parseInt($('#page_no').val());
var lastPage = parseInt($('#totalPages').text());
if (currPage < lastPage) {
$('#page_no').val(currPage + 1);
$('#searchForm').submit();
}
});
$('.previous').click(function() {
var currPage = parseInt($('#page_no').val());
if (currPage > 1) {
$('#page_no').val(currPage - 1);
$('#searchForm').submit();
}
});
/* pagination code end */
function getRow(props) {
var $tr = $('<tr />');
var $tr = $('<tr />').attr("id", "feature" + props.id).data("id", props.id).hover(function() {
var id = $(this).data("id");
var feature = getFeatureById(id);
mapControl.select(feature);
}, function() {
var id = $(this).data("id");
var feature = getFeatureById(id);
mapControl.unselect(feature);
});
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);
@ -97,6 +124,27 @@ function getRow(props) {
}
});
function onFeatureSelect(f) {
var id = f.feature.attributes.id;
// $('.highlightOverlay').hide().remove();
// $('img').removeClass('mapSelect');
var $tr = $('#feature' + id);
$tr.css({"font-weight": "bold"});
}
function onFeatureUnselect(f) {
var id = f.feature.attributes.id;
// $('.highlightOverlay').hide().remove();
// $('img').removeClass('mapSelect');
var $tr = $('#feature' + id);
$tr.css({"font-weight": "normal"});
}
/*
function getLi(props) {
var $li = $('<li />').addClass("mapListItem").attr("data-id", props.id);