// 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;
$.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 && !$('#form_fms_extra_title').length ) {
// there might be a first name field on some cobrands
var lb = $('#form_first_name').prev();
if ( lb.length == 0 ) { lb = $('#form_name').prev(); }
lb.before(data.extra_name_info);
}
});
if (!$('#side-form-error').is(':visible')) {
$('#side-form, #site-logo').show();
}
}
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; i= 13 || !$('html').hasClass('mobile') ) {
fixmystreet.map.setCenter(center, z, false, true);
}
}
});
}
var pin_layer_style_map = new OpenLayers.StyleMap({
'default': new OpenLayers.Style({
graphicTitle: "${title}",
graphicOpacity: 1,
graphicZIndex: 11,
backgroundGraphicZIndex: 10
})
});
pin_layer_style_map.addUniqueValueRules('default', 'size', {
'normal': {
externalGraphic: "/i/pin-${colour}.png",
graphicWidth: 48,
graphicHeight: 64,
graphicXOffset: -24,
graphicYOffset: -64,
backgroundGraphic: "/i/pin-shadow.png",
backgroundWidth: 60,
backgroundHeight: 30,
backgroundXOffset: -7,
backgroundYOffset: -30
},
'big': {
externalGraphic: "/i/pin-${colour}-big.png",
graphicWidth: 78,
graphicHeight: 105,
graphicXOffset: -39,
graphicYOffset: -105,
backgroundGraphic: "/i/pin-shadow-big.png",
backgroundWidth: 88,
backgroundHeight: 40,
backgroundXOffset: -10,
backgroundYOffset: -35
}
});
var pin_layer_options = {
rendererOptions: {
yOrdering: true
},
styleMap: pin_layer_style_map
};
if (fixmystreet.page == 'around') {
fixmystreet.bbox_strategy = new OpenLayers.Strategy.BBOX({ ratio: 1 });
pin_layer_options.strategies = [ fixmystreet.bbox_strategy ];
pin_layer_options.protocol = new OpenLayers.Protocol.HTTP({
url: '/ajax',
params: fixmystreet.all_pins ? { all_pins: 1 } : { },
format: new OpenLayers.Format.FixMyStreet()
});
}
fixmystreet.markers = new OpenLayers.Layer.Vector("Pins", pin_layer_options);
fixmystreet.markers.events.register( 'loadend', fixmystreet.markers, function(evt) {
if (fixmystreet.map.popups.length) fixmystreet.map.removePopup(fixmystreet.map.popups[0]);
});
var markers = fms_markers_list( fixmystreet.pins, true );
fixmystreet.markers.addFeatures( markers );
if (fixmystreet.page == 'around' || fixmystreet.page == 'reports' || fixmystreet.page == 'my') {
var select = new OpenLayers.Control.SelectFeature( fixmystreet.markers );
var selectedFeature;
function onPopupClose(evt) {
select.unselect(selectedFeature);
OpenLayers.Event.stop(evt);
}
fixmystreet.markers.events.register( 'featureunselected', fixmystreet.markers, function(evt) {
var feature = evt.feature, popup = feature.popup;
fixmystreet.map.removePopup(popup);
popup.destroy();
feature.popup = null;
});
fixmystreet.markers.events.register( 'featureselected', fixmystreet.markers, function(evt) {
var feature = evt.feature;
selectedFeature = feature;
var popup = new OpenLayers.Popup.FramedCloud("popup",
feature.geometry.getBounds().getCenterLonLat(),
null,
feature.attributes.title + "
More details",
{ size: new OpenLayers.Size(0,0), offset: new OpenLayers.Pixel(0,-40) },
true, onPopupClose);
feature.popup = popup;
fixmystreet.map.addPopup(popup);
});
fixmystreet.map.addControl( select );
select.activate();
} else if (fixmystreet.page == 'new') {
fixmystreet_activate_drag();
}
fixmystreet.map.addLayer(fixmystreet.markers);
if ( fixmystreet.zoomToBounds ) {
var bounds = fixmystreet.markers.getDataExtent();
if (bounds) {
var z = fixmystreet.map.getZoomForExtent(bounds);
if ( z >= 13 || !$('html').hasClass('mobile') ) {
fixmystreet.map.zoomToExtent( bounds );
}
}
}
$('#hide_pins_link').click(function(e) {
e.preventDefault();
var showhide = [
'Show pins', 'Hide pins',
'Dangos pinnau', 'Cuddio pinnau',
"Vis nåler", "Gjem nåler"
];
for (var i=0; i= 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
lonlat.transform(
new OpenLayers.Projection("EPSG:4326"),
fixmystreet.map.getProjectionObject()
);
var p = fixmystreet.map.getViewPortPxFromLonLat(lonlat);
p.x -= ( o.left - bo.left + w ) / 2;
lonlat = fixmystreet.map.getLonLatFromViewPortPx(p);
fixmystreet.map.panTo(lonlat);
}
}
$('#sub_map_links').hide();
if ($('html').hasClass('mobile')) {
var $map_box = $('#map_box'),
width = $map_box.width(),
height = $map_box.height();
$map_box.append(
'' +
'Try again' +
'OK' +
'
'
).css({ position: 'relative', width: width, height: height, marginBottom: '1em' });
// Making it relative here makes it much easier to do the scrolling later
$('.mobile-map-banner').text('Right place?');
// mobile user clicks 'ok' on map
$('#mob_ok').toggle(function(){
//scroll the height of the map box instead of the offset
//of the #side-form or whatever as we will probably want
//to do this on other pages where #side-form might not be
$('html, body').animate({ scrollTop: height-60 }, 1000, function(){
$('#mob_sub_map_links').addClass('map_complete');
$('#mob_ok').text('MAP');
});
}, function(){
$('html, body').animate({ scrollTop: 0 }, 1000, function(){
$('#mob_sub_map_links').removeClass('map_complete');
$('#mob_ok').text('OK');
});
});
}
fixmystreet.page = 'new';
location.hash = 'report';
}
});