From 9f873b3538b6bf23064ec7a51df3841500e67377 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Tue, 8 May 2012 18:22:23 +0100 Subject: sort out map scrolling when click where sidebar will be --- web/js/map-OpenLayers.js | 2 ++ 1 file changed, 2 insertions(+) (limited to 'web/js/map-OpenLayers.js') diff --git a/web/js/map-OpenLayers.js b/web/js/map-OpenLayers.js index 1574754c9..a215e923e 100644 --- a/web/js/map-OpenLayers.js +++ b/web/js/map-OpenLayers.js @@ -466,6 +466,8 @@ OpenLayers.Control.Click = OpenLayers.Class(OpenLayers.Control, { // e.xy is relative to top left of map, which might not be top left of page e.xy.x += bo.left; e.xy.y += bo.top; + + // 24 and 64 is the width and height of the marker pin if (e.xy.y <= o.top || (e.xy.x >= o.left && e.xy.x <= o.left + w + 24 && e.xy.y >= o.top && e.xy.y <= o.top + h + 64)) { // top of the page, pin hidden by header; // or underneath where the new sidebar will appear -- cgit v1.2.3 From 69284dad6f9b645eff9abe84b09463c0bf32fc24 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Fri, 18 May 2012 12:15:55 +0100 Subject: Work much better if reporting pin is clicked/dragged outside council boundary --- web/js/map-OpenLayers.js | 45 +++++++++++++++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 14 deletions(-) (limited to 'web/js/map-OpenLayers.js') diff --git a/web/js/map-OpenLayers.js b/web/js/map-OpenLayers.js index 20c2ea720..4e728e5f8 100644 --- a/web/js/map-OpenLayers.js +++ b/web/js/map-OpenLayers.js @@ -7,6 +7,32 @@ function fixmystreet_update_pin(lonlat) { ); document.getElementById('fixmystreet.latitude').value = lonlat.lat || lonlat.y; document.getElementById('fixmystreet.longitude').value = lonlat.lon || lonlat.x; + + $.getJSON('/report/new/ajax', { + latitude: $('#fixmystreet\\.latitude').val(), + longitude: $('#fixmystreet\\.longitude').val() + }, function(data) { + if (data.error) { + if (!$('#side-form-error').length) { + $('
').insertAfter($('#side-form')); + } + $('#side-form-error').html('

Reporting a problem

' + data.error + '

').show(); + $('#side-form').hide(); + return; + } + $('#side-form, #site-logo').show(); + $('#councils_text').html(data.councils_text); + $('#form_category_row').html(data.category); + if ( data.extra_name_info ) { + // there might be a first name field on some cobrands + var lb = $('#form_first_name').prev() || $('#form_name').prev(); + lb.before(data.extra_name_info); + } + }); + + if (!$('#side-form-error').is(':visible')) { + $('#side-form, #site-logo').show(); + } } function fixmystreet_activate_drag() { @@ -421,7 +447,6 @@ OpenLayers.Control.Click = OpenLayers.Class(OpenLayers.Control, { fixmystreet.markers.addFeatures( markers ); fixmystreet_activate_drag(); } - fixmystreet_update_pin(lonlat); // check to see if markers are visible. We click the // link so that it updates the text in case they go // back @@ -429,23 +454,15 @@ OpenLayers.Control.Click = OpenLayers.Class(OpenLayers.Control, { fixmystreet.state_pins_were_hidden = true; $('#hide_pins_link').click(); } + + // Store pin location in form fields, and check coverage of point + fixmystreet_update_pin(lonlat); + + // Already did this first time map was clicked, so no need to do it again. if (fixmystreet.page == 'new') { return; } - $.getJSON('/report/new/ajax', { - latitude: $('#fixmystreet\\.latitude').val(), - longitude: $('#fixmystreet\\.longitude').val() - }, function(data) { - if (data.error) { - // XXX If they then click back and click somewhere in the area, this error will still show. - $('#side-form').html('

Reporting a problem

' + data.error + '

'); - return; - } - $('#councils_text').html(data.councils_text); - $('#form_category_row').html(data.category); - }); - $('#side-form, #site-logo').show(); fixmystreet.map.updateSize(); // might have done, and otherwise Firefox gets confused. /* For some reason on IOS5 if you use the jQuery show method it * doesn't display the JS validation error messages unless you do this -- cgit v1.2.3 From aa59f68fcb9b26673662033c4c2d72835420ab4a Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Fri, 18 May 2012 12:38:33 +0100 Subject: do not zoom out too far onby default on around page on mobile as it gets very cluttered --- web/js/map-OpenLayers.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'web/js/map-OpenLayers.js') diff --git a/web/js/map-OpenLayers.js b/web/js/map-OpenLayers.js index 4e728e5f8..35020e1f7 100644 --- a/web/js/map-OpenLayers.js +++ b/web/js/map-OpenLayers.js @@ -82,7 +82,11 @@ function fixmystreet_onload() { var bounds = area.getDataExtent(); if (bounds) { var center = bounds.getCenterLonLat(); - fixmystreet.map.setCenter(center, fixmystreet.map.getZoomForExtent(bounds), false, true); + var z = fixmystreet.map.getZoomForExtent(bounds); + if ( z < 13 && $('html').hasClass('mobile') ) { + z = 13; + } + fixmystreet.map.setCenter(center, z, false, true); } }); } @@ -177,7 +181,14 @@ function fixmystreet_onload() { if ( fixmystreet.zoomToBounds ) { var bounds = fixmystreet.markers.getDataExtent(); - if (bounds) { fixmystreet.map.zoomToExtent( bounds ); } + if (bounds) { + var center = bounds.getCenterLonLat(); + var z = fixmystreet.map.getZoomForExtent(bounds); + if ( z < 13 && $('html').hasClass('mobile') ) { + z = 13; + } + fixmystreet.map.setCenter(center, z); + } } $('#hide_pins_link').click(function(e) { -- cgit v1.2.3