1 |
1 |
$(function() {
|
2 |
|
function render_map(container) {
|
3 |
|
$container = $(container);
|
4 |
|
$container.find('div div.combo-cell-map').each(function() {
|
5 |
|
var $map_widget = $(this);
|
6 |
|
var map_options = Object();
|
7 |
|
var initial_zoom = parseInt($map_widget.data('init-zoom'));
|
8 |
|
if (! isNaN(initial_zoom)) {
|
9 |
|
map_options.zoom = initial_zoom;
|
10 |
|
} else {
|
11 |
|
map_options.zoom = 13;
|
12 |
|
}
|
13 |
|
var max_zoom = parseInt($map_widget.data('max_zoom'));
|
14 |
|
if (!isNaN(max_zoom)) map_options.maxZoom = max_zoom;
|
15 |
|
var min_zoom = parseInt($map_widget.data('min-zoom'));
|
16 |
|
if (!isNaN(min_zoom)) map_options.minZoom = min_zoom;
|
17 |
|
var latlng = [$map_widget.data('init-lat'), $map_widget.data('init-lng')];
|
18 |
|
var geojson_url = $map_widget.data('geojson-url');
|
19 |
|
var map_tile_url = $map_widget.data('tile-urltemplate');
|
20 |
|
var map_attribution = $map_widget.data('map-attribution');
|
21 |
|
var map = L.map(this, map_options);
|
22 |
|
var store_position_selector = $map_widget.data('store-position');
|
23 |
|
map.setView(latlng, map_options.zoom);
|
|
2 |
function render_map(cell) {
|
|
3 |
var $map_widget = $(cell).find('div.combo-cell-map');
|
|
4 |
var map_options = Object();
|
|
5 |
var initial_zoom = parseInt($map_widget.data('init-zoom'));
|
|
6 |
if (! isNaN(initial_zoom)) {
|
|
7 |
map_options.zoom = initial_zoom;
|
|
8 |
} else {
|
|
9 |
map_options.zoom = 13;
|
|
10 |
}
|
|
11 |
var max_zoom = parseInt($map_widget.data('max_zoom'));
|
|
12 |
if (!isNaN(max_zoom)) map_options.maxZoom = max_zoom;
|
|
13 |
var min_zoom = parseInt($map_widget.data('min-zoom'));
|
|
14 |
if (!isNaN(min_zoom)) map_options.minZoom = min_zoom;
|
|
15 |
var latlng = [$map_widget.data('init-lat'), $map_widget.data('init-lng')];
|
|
16 |
var geojson_url = $map_widget.data('geojson-url');
|
|
17 |
var map_tile_url = $map_widget.data('tile-urltemplate');
|
|
18 |
var map_attribution = $map_widget.data('map-attribution');
|
|
19 |
var map = L.map($map_widget[0], map_options);
|
|
20 |
var store_position_selector = $map_widget.data('store-position');
|
|
21 |
map.setView(latlng, map_options.zoom);
|
24 |
22 |
|
25 |
|
L.tileLayer(map_tile_url,
|
26 |
|
{
|
27 |
|
attribution: map_attribution
|
28 |
|
}).addTo(map);
|
29 |
|
if (geojson_url) {
|
30 |
|
$.getJSON(geojson_url, function(data) {
|
31 |
|
var geo_json = L.geoJson(data, {
|
32 |
|
onEachFeature: function(feature, layer) {
|
33 |
|
$map_widget.trigger('combo:map-feature-click', feature, layer);
|
34 |
|
},
|
35 |
|
pointToLayer: function (feature, latlng) {
|
36 |
|
var markerStyles = "background-color: "+feature.properties.colour+";";
|
37 |
|
marker = L.divIcon({iconAnchor: [0, 30],
|
38 |
|
popupAnchor: [5, -45],
|
39 |
|
html: '<span style="' + markerStyles + '"><i class="leaflet-marker-icon '+feature.properties.icon+'" style="color:'+feature.properties.icon_colour+'"></i></span>'
|
40 |
|
});
|
41 |
|
return L.marker(latlng, {icon: marker});
|
42 |
|
}
|
43 |
|
});
|
44 |
|
var bounds = geo_json.getBounds();
|
45 |
|
if (bounds.isValid()) {
|
46 |
|
map.fitBounds(bounds);
|
47 |
|
geo_json.addTo(map);
|
|
23 |
L.tileLayer(map_tile_url,
|
|
24 |
{
|
|
25 |
attribution: map_attribution
|
|
26 |
}).addTo(map);
|
|
27 |
if (geojson_url) {
|
|
28 |
$.getJSON(geojson_url, function(data) {
|
|
29 |
var geo_json = L.geoJson(data, {
|
|
30 |
onEachFeature: function(feature, layer) {
|
|
31 |
$(cell).trigger('combo:map-feature-click', {'feature': feature, 'layer': layer});
|
|
32 |
},
|
|
33 |
pointToLayer: function (feature, latlng) {
|
|
34 |
var markerStyles = "background-color: "+feature.properties.colour+";";
|
|
35 |
marker = L.divIcon({iconAnchor: [0, 30],
|
|
36 |
popupAnchor: [5, -45],
|
|
37 |
html: '<span style="' + markerStyles + '"><i class="leaflet-marker-icon '+feature.properties.icon+'" style="color:'+feature.properties.icon_colour+'"></i></span>'
|
|
38 |
});
|
|
39 |
return L.marker(latlng, {icon: marker});
|
48 |
40 |
}
|
49 |
41 |
});
|
50 |
|
}
|
51 |
|
});
|
|
42 |
var bounds = geo_json.getBounds();
|
|
43 |
if (bounds.isValid()) {
|
|
44 |
map.fitBounds(bounds);
|
|
45 |
geo_json.addTo(map);
|
|
46 |
}
|
|
47 |
});
|
|
48 |
}
|
52 |
49 |
};
|
53 |
|
$('div.combo-cell-map').parents('div.cell').on('combo:cellform-reloaded', function() {
|
|
50 |
$('div.cell.map').each(function() {
|
54 |
51 |
render_map(this);
|
55 |
52 |
});
|
56 |
|
$('div.combo-cell-map').parents('div.cell').each(function() {
|
57 |
|
$(this).trigger('combo:cellform-reloaded');
|
58 |
|
});
|
59 |
53 |
});
|
60 |
|
-
|