aboutsummaryrefslogtreecommitdiffstats
path: root/web/js/map-OpenLayers.js
diff options
context:
space:
mode:
Diffstat (limited to 'web/js/map-OpenLayers.js')
-rw-r--r--web/js/map-OpenLayers.js56
1 files changed, 46 insertions, 10 deletions
diff --git a/web/js/map-OpenLayers.js b/web/js/map-OpenLayers.js
index f8bd9c31e..d3914a128 100644
--- a/web/js/map-OpenLayers.js
+++ b/web/js/map-OpenLayers.js
@@ -41,6 +41,17 @@ $(function(){
return false;
});
+ $(window).hashchange(function(){
+ if (location.hash) return;
+ // Okay, back to around view.
+ fixmystreet.bbox_strategy.activate();
+ fixmystreet.markers.refresh( { force: true } );
+ fixmystreet.drag.deactivate();
+ $('#side-form').hide();
+ $('#side').show();
+ fixmystreet.page = 'around';
+ });
+
// Vector layers must be added onload as IE sucks
if ($.browser.msie) {
$(window).load(fixmystreet_onload);
@@ -79,7 +90,8 @@ function fixmystreet_onload() {
})
};
if (fixmystreet.page == 'around') {
- pin_layer_options.strategies = [ new OpenLayers.Strategy.BBOX() ];
+ fixmystreet.bbox_strategy = new OpenLayers.Strategy.BBOX();
+ pin_layer_options.strategies = [ fixmystreet.bbox_strategy ];
pin_layer_options.protocol = new OpenLayers.Protocol.HTTP({
url: '/ajax',
params: fixmystreet.all_pins ? { all_pins: 1 } : { },
@@ -92,20 +104,16 @@ function fixmystreet_onload() {
fixmystreet.markers.addFeatures( markers );
if (fixmystreet.page == 'around' || fixmystreet.page == 'reports' || fixmystreet.page == 'my') {
fixmystreet.markers.events.register( 'featureselected', fixmystreet.markers, function(evt) {
- window.location = '/report/' + evt.feature.attributes.id;
+ if (evt.feature.attributes.id) {
+ window.location = '/report/' + evt.feature.attributes.id;
+ }
OpenLayers.Event.stop(evt);
});
var select = new OpenLayers.Control.SelectFeature( fixmystreet.markers );
fixmystreet.map.addControl( select );
select.activate();
} else if (fixmystreet.page == 'new') {
- var drag = new OpenLayers.Control.DragFeature( fixmystreet.markers, {
- onComplete: function(feature, e) {
- fixmystreet_update_pin( feature.geometry.clone() );
- }
- } );
- fixmystreet.map.addControl( drag );
- drag.activate();
+ fixmystreet_activate_drag();
}
fixmystreet.map.addLayer(fixmystreet.markers);
@@ -287,13 +295,30 @@ OpenLayers.Control.Click = OpenLayers.Class(OpenLayers.Control, {
trigger: function(e) {
var lonlat = fixmystreet.map.getLonLatFromViewPortPx(e.xy);
if (fixmystreet.page == 'new') {
+ /* Already have a purple pin */
fixmystreet.markers.features[0].move(lonlat);
+ } else {
+ var markers = fms_markers_list( [ [ lonlat.lat, lonlat.lon, 'purple' ] ], false );
+ fixmystreet.bbox_strategy.deactivate();
+ fixmystreet.markers.removeAllFeatures();
+ fixmystreet.markers.addFeatures( markers );
+ fixmystreet_activate_drag();
}
fixmystreet_update_pin(lonlat);
if (fixmystreet.page == 'new') {
return;
}
- document.getElementById('mapForm').submit();
+ $.getJSON('/report/new/ajax', {
+ latitude: $('#fixmystreet\\.latitude').val(),
+ longitude: $('#fixmystreet\\.longitude').val()
+ }, function(data) {
+ $('#councils_text').html(data.councils_text);
+ $('#form_category_row').html(data.category);
+ });
+ $('#side-form').show();
+ $('#side').hide();
+ fixmystreet.page = 'new';
+ location.hash = 'report';
}
});
@@ -307,3 +332,14 @@ function fixmystreet_update_pin(lonlat) {
document.getElementById('fixmystreet.latitude').value = lonlat.lat || lonlat.y;
document.getElementById('fixmystreet.longitude').value = lonlat.lon || lonlat.x;
}
+
+function fixmystreet_activate_drag() {
+ fixmystreet.drag = new OpenLayers.Control.DragFeature( fixmystreet.markers, {
+ onComplete: function(feature, e) {
+ fixmystreet_update_pin( feature.geometry.clone() );
+ }
+ } );
+ fixmystreet.map.addControl( fixmystreet.drag );
+ fixmystreet.drag.activate();
+}
+