Skip to content

Commit 885d786

Browse files
committed
Upgrade Leaflet to version 0.7.2 and plugins MarkerCluster,Search,contextmenu,providers,EditInOSM
1 parent c2f51d2 commit 885d786

17 files changed

Lines changed: 966 additions & 89 deletions

leaflet/Leaflet.EditInOSM.css

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
.leaflet-control-edit-in-osm {
2+
background: none repeat scroll 0 0 #F8F8F9;
3+
border: 1px solid #888888;
4+
border-radius: 5px 5px 5px 5px;
5+
box-shadow: 0 0 8px rgba(0, 0, 0, 0.4);
6+
}
7+
.leaflet-control-edit-in-osm .leaflet-control-edit-in-osm-toggle {
8+
background-position: 50% 50%;
9+
background-repeat: no-repeat;
10+
height: 36px;
11+
width: 36px;
12+
display: block;
13+
}
14+
.leaflet-control-edit-in-osm .leaflet-control-edit-in-osm-toggle {
15+
background-image: url("images/edit-in-osm.png");
16+
}
17+
.leaflet-control-edit-in-osm .osm-editor + .osm-editor {
18+
border-left: 1px solid black;
19+
}
20+
.leaflet-control-edit-in-osm a.osm-editor {
21+
display: none;
22+
height: 36px;
23+
min-width: 36px;
24+
text-align: center;
25+
line-height: 36px;
26+
color: #333;
27+
padding: 0 5px;
28+
text-decoration: none;
29+
font-family: sans-serif;
30+
}
31+
.leaflet-control-edit-in-osm:hover a.osm-editor {
32+
display: inline-block;
33+
}
34+
a.osm-editor:hover {
35+
box-shadow: 0 0 2px 0 black inset;
36+
}
37+
.leaflet-control-edit-in-osm:hover .leaflet-control-edit-in-osm-toggle {
38+
display: none;
39+
}
40+
41+
.leaflet-control-edit-hidden {
42+
display: none;
43+
}

leaflet/Leaflet.EditInOSM.js

Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
(function (L, setTimeout) {
2+
3+
var _controlContainer,
4+
_map,
5+
_zoomThreshold,
6+
_hideClass = 'leaflet-control-edit-hidden',
7+
_anchorClass = 'leaflet-control-edit-in-osm-toggle',
8+
9+
_Widgets = {
10+
MultiButton: function (config) {
11+
var className = 'leaflet-control-edit-in-osm',
12+
helpText = "Open this map extent in a map editor to provide more accurate data to OpenStreetMap",
13+
addEditors = function (container, editors) {
14+
for (var i in editors) {
15+
addEditorToWidget(container, editors[i]);
16+
}
17+
};
18+
19+
return {
20+
className: (config && config.className) || className,
21+
helpText: (config && config.helpText) || helpText,
22+
addEditors: (config && config.addEditors) || addEditors
23+
};
24+
},
25+
AttributionBox: function (config) {
26+
var className = 'leaflet-control-attribution',
27+
helpText = "Edit in OSM",
28+
addEditors = function (container, editors) {
29+
addEditorToWidget(container, editors[0], helpText);
30+
};
31+
32+
return {
33+
className: (config && config.className) || className,
34+
helpText: (config && config.helpText) || helpText,
35+
addEditors: (config && config.addEditors) || addEditors
36+
};
37+
}
38+
},
39+
40+
_Editors = {
41+
Id: function (config) {
42+
var url = 'http://openstreetmap.us/iD/release/#map=',
43+
displayName = "iD",
44+
buildUrl = function (map) {
45+
return this.url + [
46+
map.getZoom(),
47+
map.getCenter().wrap().lng,
48+
map.getCenter().wrap().lat
49+
].join('/');
50+
};
51+
return {
52+
url: (config && config.url) || url,
53+
displayName: (config && config.displayName) || displayName,
54+
buildUrl: (config && config.buildUrl) || buildUrl
55+
};
56+
},
57+
Josm: function (config) {
58+
var url = 'http://127.0.0.1:8111/load_and_zoom',
59+
timeout = 1000,
60+
displayName = "JOSM",
61+
buildUrl = function (map) {
62+
var bounds = map.getBounds();
63+
return this.url + L.Util.getParamString({
64+
left: bounds.getNorthWest().lng,
65+
right: bounds.getSouthEast().lng,
66+
top: bounds.getNorthWest().lat,
67+
bottom: bounds.getSouthEast().lat
68+
});
69+
};
70+
71+
return {
72+
url: (config && config.url) || url,
73+
timeout: (config && config.timeout) || timeout,
74+
displayName: (config && config.displayName) || displayName,
75+
buildUrl: (config && config.buildUrl) || buildUrl
76+
};
77+
},
78+
Potlatch: function (config) {
79+
var url = 'http://open.mapquestapi.com/dataedit/index_flash.html',
80+
displayName = "P2",
81+
buildUrl = function (map) {
82+
return this.url + L.Util.getParamString({
83+
lon: map.getCenter().wrap().lng,
84+
lat: map.getCenter().wrap().lat,
85+
zoom: map.getZoom()
86+
});
87+
};
88+
return {
89+
url: (config && config.url) || url,
90+
displayName: (config && config.displayName) || displayName,
91+
buildUrl: (config && config.buildUrl) || buildUrl
92+
};
93+
}
94+
};
95+
96+
97+
// Takes an editor, calls their buildUrl method
98+
// and opens the url in the browser
99+
function openRemote (editor) {
100+
var url = editor.buildUrl(_map),
101+
w = window.open(url);
102+
if (editor.timeout) {
103+
setTimeout(function() {w.close();}, editor.timeout);
104+
}
105+
}
106+
107+
function addEditorToWidget(widgetContainer, editor, text) {
108+
var editorWidget = L.DomUtil.create('a', "osm-editor", widgetContainer);
109+
editorWidget.href = "#";
110+
editorWidget.innerHTML = text || editor.displayName;
111+
L.DomEvent.on(editorWidget, "click", function (e) {
112+
openRemote(editor);
113+
L.DomEvent.stop(e);
114+
});
115+
}
116+
117+
// Make the EditInOSM widget visible or invisible after each
118+
// zoom event.
119+
//
120+
// configurable by setting the *zoomThreshold* option.
121+
function showOrHideUI() {
122+
var zoom = _map.getZoom();
123+
if (zoom < _zoomThreshold) {
124+
L.DomUtil.addClass(_controlContainer, _hideClass);
125+
} else {
126+
L.DomUtil.removeClass(_controlContainer, _hideClass);
127+
}
128+
}
129+
130+
L.Control.EditInOSM = L.Control.extend({
131+
132+
options: {
133+
position: "topright",
134+
zoomThreshold: 0,
135+
widget: "multiButton",
136+
editors: ["id", "josm"]
137+
},
138+
139+
initialize: function (options) {
140+
var newEditors = [],
141+
widget,
142+
widgetSmallName,
143+
editor,
144+
editorSmallName;
145+
146+
L.setOptions(this, options);
147+
148+
_zoomThreshold = this.options.zoomThreshold;
149+
150+
widget = this.options.widget;
151+
widgetSmallName = typeof(widget) === 'string' ? widget.toLowerCase() : '';
152+
153+
// setup widget from string or object
154+
if (widgetSmallName === "multibutton") {
155+
this.options.widget = new _Widgets.MultiButton();
156+
} else if (widgetSmallName === "attributionbox") {
157+
this.options.widget = new _Widgets.AttributionBox();
158+
}
159+
160+
// setup editors from strings or objects
161+
for (var i in this.options.editors) {
162+
editor = this.options.editors[i],
163+
editorSmallName = typeof(editor) === "string" ? editor.toLowerCase() : null;
164+
165+
if (editorSmallName === "id") {
166+
newEditors.push(new _Editors.Id());
167+
} else if (editorSmallName === "josm") {
168+
newEditors.push(new _Editors.Josm());
169+
} else if (editorSmallName === "potlatch") {
170+
newEditors.push(new _Editors.Potlatch());
171+
} else {
172+
newEditors.push(editor);
173+
}
174+
}
175+
this.options.editors = newEditors;
176+
177+
},
178+
179+
onAdd: function (map) {
180+
_map = map;
181+
map.on('zoomend', showOrHideUI);
182+
183+
_controlContainer = L.DomUtil.create('div', this.options.widget.className);
184+
185+
_controlContainer.title = this.options.widget.helpText || '';
186+
187+
L.DomUtil.create('a', _anchorClass, _controlContainer);
188+
189+
this.options.widget.addEditors(_controlContainer, this.options.editors);
190+
return _controlContainer;
191+
},
192+
193+
onRemove: function (map) {
194+
map.off('zoomend', this._onZoomEnd);
195+
}
196+
197+
});
198+
199+
L.Control.EditInOSM.Widgets = _Widgets;
200+
L.Control.EditInOSM.Editors = _Editors;
201+
202+
L.Map.addInitHook(function () {
203+
if (this.options.editInOSMControlOptions) {
204+
var options = this.options.editInOSMControlOptions || {};
205+
this.editInOSMControl = (new L.Control.EditInOSM(options)).addTo(this);
206+
}
207+
});
208+
209+
})(L, setTimeout);

leaflet/MarkerCluster.css

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.leaflet-cluster-anim .leaflet-marker-icon, .leaflet-cluster-anim .leaflet-marker-shadow {
2-
-webkit-transition: -webkit-transform 0.2s ease-out, opacity 0.2s ease-in;
3-
-moz-transition: -moz-transform 0.2s ease-out, opacity 0.2s ease-in;
4-
-o-transition: -o-transform 0.2s ease-out, opacity 0.2s ease-in;
5-
transition: transform 0.2s ease-out, opacity 0.2s ease-in;
2+
-webkit-transition: -webkit-transform 0.3s ease-out, opacity 0.3s ease-in;
3+
-moz-transition: -moz-transform 0.3s ease-out, opacity 0.3s ease-in;
4+
-o-transition: -o-transform 0.3s ease-out, opacity 0.3s ease-in;
5+
transition: transform 0.3s ease-out, opacity 0.3s ease-in;
66
}

leaflet/images/edit-in-osm.png

3.26 KB
Loading

leaflet/leaflet-providers.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,17 @@
115115
}
116116
},
117117
OpenMapSurfer: {
118-
url: 'http://129.206.74.245:8001/tms_r.ashx?x={x}&y={y}&z={z}',
118+
url: 'http://openmapsurfer.uni-hd.de/tiles/roads/x={x}&y={y}&z={z}',
119119
options: {
120120
attribution: 'Imagery from <a href="http://giscience.uni-hd.de/">GIScience Research Group @ University of Heidelberg</a> &mdash; Map data {attribution.OpenStreetMap}'
121121
},
122122
variants: {
123+
Roads: {},
124+
AdminBounds: {
125+
url: 'http://openmapsurfer.uni-hd.de/tiles/adminb/x={x}&y={y}&z={z}'
126+
},
123127
Grayscale: {
124-
url: 'http://129.206.74.245:8008/tms_rg.ashx?x={x}&y={y}&z={z}'
128+
url: 'http://openmapsurfer.uni-hd.de/tiles/roadsg/x={x}&y={y}&z={z}'
125129
}
126130
}
127131
},

leaflet/leaflet-search.min.css

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)