-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
114 lines (99 loc) · 2.89 KB
/
index.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
var geoMap = 0;
ymaps.ready(function() {
geoMap = new ymaps.Map('map', {
center: [59.969718, 30.316536],
type: "yandex#map",
zoom: 10
}, {
geoObjectBalloonPanelMapMaxArea: Infinity
});
var depth = [],
names = {};
function buildAddr() {
var d = $(".legend");
d.html('');
for (var i in depth) {
(function(i) {
var name = depth[i];
var oname = names[name] || name;
var l = $("<a href='#'>" + oname + "</a>");
l.click(function() {
depth.length = i;
load(name);
});
l.appendTo(d);
})(i);
}
}
var lastCollection = 0;
function load(addr, callback) {
osmeRegions.geoJSON(addr, {
lang: 'ru'
}, function(data) {
var thisId = data.metaData.osmId;
var list = [];
for (var i in data.features) {
var iso = '';
if (data.features[i].properties.properties.iso3166) {
iso = ' (' + data.features[i].properties.properties.iso3166 + ')';
}
list.push("<li>" + data.features[i].properties.name + iso + "</li>");
if (data.features[i].properties.osmId == thisId) {
names[addr] = data.features[i].properties.name;
}
}
$(".regionList").html("<ul>" + list.join('') + "</ul>");
depth.push(addr);
buildAddr();
var collection = osmeRegions.toYandex(data, ymaps);
if (lastCollection) {
lastCollection.remove(geoMap);
}
lastCollection = collection;
collection.add(geoMap);
geoMap.setBounds(collection.collection.getBounds(), {
duration: 300
});
var strokeColors = [
'#000',
'#F0F',
'#00F',
'#0FF',
];
var meta = data.metaData,
// minLevel = meta.levels[0],
maxLevel = meta.levels[1] + 1;
collection.setStyles(function(object, yobject) {
var level = object.properties.level;
// console.log(object);
yobject.properties.set('balloonContent', "<div style=''>" + JSON.stringify(object.properties).split(',').join(", ") + "</div>");
return ({
zIndex: level,
zIndexHover: level,
strokeWidth: Math.max(1, level == 2 ? 2 : (maxLevel - level)),
strokeColor: strokeColors[maxLevel - level] || '#000',
fillColor: get_color(object),
balloonPanelMaxMapArea: Infinity,
balloonAutoPan: false,
autoPanDuration: 5000,
draggable: false
});
});
collection.addEvent('dblclick', function(object, type, target) {
var osmId = object.properties.osmId;
event.preventDefault();
if (osmId) {
geoMap.setBounds(target.geometry.getBounds());
setTimeout(function() {
load('' + osmId);
}, 1);
}
});
if (callback) {
callback();
}
});
}
load('RU');
window.rload = load;
});