-
Notifications
You must be signed in to change notification settings - Fork 194
/
Copy pathdataset_map.js
81 lines (67 loc) · 2.19 KB
/
dataset_map.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// Dataset map module
this.ckan.module('dataset-map', function (jQuery, _) {
return {
options: {
i18n: {
},
styles: {
point:{
iconUrl: '/img/marker.png',
iconSize: [14, 25],
iconAnchor: [7, 25]
},
default_:{
color: '#B52',
weight: 2,
opacity: 1,
fillColor: '#FCF6CF',
fillOpacity: 0.4
}
}
},
initialize: function () {
this.extent = this.el.data('extent');
// fix bbox when w-long is positive while e-long is negative.
// assuming coordinate sequence is west to east (left to right)
if (this.extent.type == 'Polygon'
&& this.extent.coordinates[0].length == 5) {
_coordinates = this.extent.coordinates[0]
w = _coordinates[0][0];
e = _coordinates[2][0];
if (w >= 0 && e < 0) {
w_new = w
while (w_new > e) w_new -=360
for (var i = 0; i < _coordinates.length; i++) {
if (_coordinates[i][0] == w) {
_coordinates[i][0] = w_new
};
};
this.extent.coordinates[0] = _coordinates
};
};
// hack to make leaflet use a particular location to look for images
L.Icon.Default.imagePath = this.options.site_url + 'js/vendor/leaflet/images';
jQuery.proxyAll(this, /_on/);
this.el.ready(this._onReady);
},
_onReady: function(){
var map, backgroundLayer, extentLayer, ckanIcon;
if (!this.extent) {
return false;
}
map = ckan.commonLeafletMap('dataset-map-container', this.options.map_config, {attributionControl: false});
var ckanIcon = L.Icon.extend({options: this.options.styles.point});
var extentLayer = L.geoJson(this.extent, {
style: this.options.styles.default_,
pointToLayer: function (feature, latLng) {
return new L.Marker(latLng, {icon: new ckanIcon})
}});
extentLayer.addTo(map);
if (this.extent.type == 'Point'){
map.setView(L.latLng(this.extent.coordinates[1], this.extent.coordinates[0]), 9);
} else {
map.fitBounds(extentLayer.getBounds());
}
}
}
});