1 |
1 |
$(function() {
|
|
2 |
L.Map.include(
|
|
3 |
{
|
|
4 |
add_geojson_layer: function(callback) {
|
|
5 |
var map = this;
|
|
6 |
var $map_widget = $(map.getContainer());
|
|
7 |
var cell = $map_widget.parents('div.cell')[0];
|
|
8 |
var geojson_url = $map_widget.data('geojson-url');
|
|
9 |
if (!geojson_url) return;
|
|
10 |
|
|
11 |
$.getJSON(geojson_url, function(data) {
|
|
12 |
var geo_json = L.geoJson(data, {
|
|
13 |
onEachFeature: function(feature, layer) {
|
|
14 |
$(cell).trigger('combo:map-feature-prepare', {'feature': feature, 'layer': layer});
|
|
15 |
},
|
|
16 |
pointToLayer: function (feature, latlng) {
|
|
17 |
var markerStyles = "background-color: " + feature.properties.layer.colour + ";";
|
|
18 |
marker = L.divIcon({iconAnchor: [0, 30],
|
|
19 |
popupAnchor: [5, -45],
|
|
20 |
html: '<span style="' + markerStyles + '"><i class="leaflet-marker-icon ' +
|
|
21 |
feature.properties.layer.icon + '" style="color:' +
|
|
22 |
feature.properties.layer.icon_colour +'"></i></span>'
|
|
23 |
});
|
|
24 |
return L.marker(latlng, {icon: marker});
|
|
25 |
}
|
|
26 |
});
|
|
27 |
if (map.geo_json) map.geo_json.remove();
|
|
28 |
map.geo_json = geo_json;
|
|
29 |
geo_json.addTo(map);
|
|
30 |
if (callback) {
|
|
31 |
callback(geo_json);
|
|
32 |
}
|
|
33 |
});
|
|
34 |
}
|
|
35 |
});
|
|
36 |
|
2 |
37 |
function render_map(cell) {
|
3 |
38 |
var $map_widget = $(cell).find('div.combo-cell-map');
|
4 |
39 |
var map_options = Object();
|
... | ... | |
24 |
59 |
var map = L.map($map_widget[0], map_options);
|
25 |
60 |
var store_position_selector = $map_widget.data('store-position');
|
26 |
61 |
|
|
62 |
$map_widget[0].leaflet_map = map;
|
27 |
63 |
map.setView(latlng, map_options.zoom);
|
28 |
64 |
|
29 |
65 |
if (init_state == 'device-location') {
|
... | ... | |
38 |
74 |
attribution: map_attribution,
|
39 |
75 |
maxZoom: map_options.maxZoom
|
40 |
76 |
}).addTo(map);
|
41 |
|
if (geojson_url) {
|
42 |
|
$.getJSON(geojson_url, function(data) {
|
43 |
|
var geo_json = L.geoJson(data, {
|
44 |
|
onEachFeature: function(feature, layer) {
|
45 |
|
$(cell).trigger('combo:map-feature-prepare', {'feature': feature, 'layer': layer});
|
46 |
|
},
|
47 |
|
pointToLayer: function (feature, latlng) {
|
48 |
|
var markerStyles = "background-color: " + feature.properties.layer.colour + ";";
|
49 |
|
marker = L.divIcon({iconAnchor: [0, 30],
|
50 |
|
popupAnchor: [5, -45],
|
51 |
|
html: '<span style="' + markerStyles + '"><i class="leaflet-marker-icon ' +
|
52 |
|
feature.properties.layer.icon + '" style="color:' +
|
53 |
|
feature.properties.layer.icon_colour +'"></i></span>'
|
54 |
|
});
|
55 |
|
return L.marker(latlng, {icon: marker});
|
56 |
|
}
|
57 |
|
});
|
58 |
|
var bounds = geo_json.getBounds();
|
59 |
|
if (bounds.isValid()) {
|
60 |
|
if (init_state == 'fit-markers') {
|
61 |
|
map.fitBounds(bounds);
|
62 |
|
}
|
63 |
|
geo_json.addTo(map);
|
|
77 |
map.add_geojson_layer(function(geo_json) {
|
|
78 |
var bounds = geo_json.getBounds();
|
|
79 |
if (bounds.isValid()) {
|
|
80 |
if (init_state == 'fit-markers') {
|
|
81 |
map.fitBounds(bounds);
|
64 |
82 |
}
|
65 |
|
});
|
66 |
|
}
|
|
83 |
}
|
|
84 |
});
|
67 |
85 |
};
|
68 |
86 |
$('div.cell.map').each(function() {
|
69 |
87 |
render_map(this);
|
70 |
|
-
|