54 lines
2.4 KiB
JavaScript
54 lines
2.4 KiB
JavaScript
$(function() {
|
|
function render_map(cell) {
|
|
var $map_widget = $(cell).find('div.combo-cell-map');
|
|
var map_options = Object();
|
|
var initial_zoom = parseInt($map_widget.data('init-zoom'));
|
|
if (! isNaN(initial_zoom)) {
|
|
map_options.zoom = initial_zoom;
|
|
} else {
|
|
map_options.zoom = 13;
|
|
}
|
|
var max_zoom = parseInt($map_widget.data('max_zoom'));
|
|
if (!isNaN(max_zoom)) map_options.maxZoom = max_zoom;
|
|
var min_zoom = parseInt($map_widget.data('min-zoom'));
|
|
if (!isNaN(min_zoom)) map_options.minZoom = min_zoom;
|
|
var latlng = [$map_widget.data('init-lat'), $map_widget.data('init-lng')];
|
|
var geojson_url = $map_widget.data('geojson-url');
|
|
var map_tile_url = $map_widget.data('tile-urltemplate');
|
|
var map_attribution = $map_widget.data('map-attribution');
|
|
var map = L.map($map_widget[0], map_options);
|
|
var store_position_selector = $map_widget.data('store-position');
|
|
map.setView(latlng, map_options.zoom);
|
|
|
|
L.tileLayer(map_tile_url,
|
|
{
|
|
attribution: map_attribution
|
|
}).addTo(map);
|
|
if (geojson_url) {
|
|
$.getJSON(geojson_url, function(data) {
|
|
var geo_json = L.geoJson(data, {
|
|
onEachFeature: function(feature, layer) {
|
|
$(cell).trigger('combo:map-feature-click', {'feature': feature, 'layer': layer});
|
|
},
|
|
pointToLayer: function (feature, latlng) {
|
|
var markerStyles = "background-color: "+feature.properties.colour+";";
|
|
marker = L.divIcon({iconAnchor: [0, 30],
|
|
popupAnchor: [5, -45],
|
|
html: '<span style="' + markerStyles + '"><i class="leaflet-marker-icon '+feature.properties.icon+'" style="color:'+feature.properties.icon_colour+'"></i></span>'
|
|
});
|
|
return L.marker(latlng, {icon: marker});
|
|
}
|
|
});
|
|
var bounds = geo_json.getBounds();
|
|
if (bounds.isValid()) {
|
|
map.fitBounds(bounds);
|
|
geo_json.addTo(map);
|
|
}
|
|
});
|
|
}
|
|
};
|
|
$('div.cell.map').each(function() {
|
|
render_map(this);
|
|
});
|
|
});
|