// This function might be passed either an OpenLayers.LonLat (so has // lon and lat) or an OpenLayers.Geometry.Point (so has x and y) function fixmystreet_update_pin(lonlat) { lonlat.transform( fixmystreet.map.getProjectionObject(), new OpenLayers.Projection("EPSG:4326") ); 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(); } function fms_markers_list(pins, transform) { var markers = []; for (var i=0; iClose'); $('.big-green-banner').addClass('mobile-map-banner'); // hide site-logo (z-index madness), show sub_map_links // and push map zoom down a notch $('#site-logo').hide(); $('#sub_map_links').show(); $('#fms_pan_zoom').css({'top':'3.5em !important'}); // need to set up a click for #close-mobile-map somehow fixmystreet.map.updateSize(); fixmystreet.page = 'mobile-full-map'; // To make sure the click control is on top this.deactivate(); this.activate(); }, locate_report: function(e) { var lonlat = fixmystreet.map.getLonLatFromViewPortPx(e.xy); if (fixmystreet.page == 'new') { /* Already have a pin */ fixmystreet.markers.features[0].move(lonlat); } else { var markers = fms_markers_list( [ [ lonlat.lat, lonlat.lon, 'yellow' ] ], false ); fixmystreet.bbox_strategy.deactivate(); fixmystreet.markers.removeAllFeatures(); 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 if ( ! fixmystreet.markers.getVisibility() ) { $('#hide_pins_link').click(); } if (fixmystreet.page == 'new') { return; } $.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); /* Need to reset this here as it gets removed when we replace the HTML for the dropdown */ if ( data.has_open311 > 0 ) { $('#form_category').change( form_category_onchange ); } }); $('#side-form, #site-logo').show(); /* 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 * or you cause a screen redraw by changing the phone orientation. * NB: This has to happen after the call to show() */ if ( navigator.userAgent.match(/like Mac OS X/i)) { document.getElementById('side-form').style.display = 'block'; } $('#side').hide(); //hide lots of the map ui on mobile $('#sub_map_links, #fms_pan_zoom, #close-mobile-map', '.mobile').hide(); heightFix('#report-a-problem-sidebar:visible', '.content', 26); // If we clicked the map somewhere inconvenient var sidebar = $('#report-a-problem-sidebar'); if (sidebar.css('position') == 'absolute') { var w = sidebar.width(), h = sidebar.height(), o = sidebar.offset(); if (e.xy.y <= o.top) { // top of the page, pin hidden by header lonlat.transform( new OpenLayers.Projection("EPSG:4326"), fixmystreet.map.getProjectionObject() ); fixmystreet.map.setCenter(lonlat, fixmystreet.map.getZoom(), true, true); } else if (e.xy.x >= o.left && e.xy.x <= o.left + w + 24 && e.xy.y >= o.top && e.xy.y <= o.top + h + 64) { // underneath where the new sidebar will appear fixmystreet.map.pan(-w, 0, { animate: false }); } } if (fixmystreet.page == 'mobile-full-map') { lonlat.transform( new OpenLayers.Projection("EPSG:4326"), fixmystreet.map.getProjectionObject() ); fixmystreet.map.setCenter(lonlat); } fixmystreet.page = 'new'; location.hash = 'report'; } });