mapstraction-rails 2.0.18.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +4 -0
- data/Gemfile.lock +14 -0
- data/LICENSE +22 -0
- data/README.md +32 -0
- data/Rakefile +2 -0
- data/lib/mapstraction/engine.rb +4 -0
- data/lib/mapstraction/version.rb +3 -0
- data/lib/mapstraction.rb +5 -0
- data/mapstraction/.gitignore +17 -0
- data/mapstraction.gemspec +17 -0
- data/vendor/.DS_Store +0 -0
- data/vendor/assets/.DS_Store +0 -0
- data/vendor/assets/javascripts/mxn-min.js +15 -0
- data/vendor/assets/javascripts/mxn.cartociudad.geocoder-min.js +15 -0
- data/vendor/assets/javascripts/mxn.cartociudad.geocoder.js +46 -0
- data/vendor/assets/javascripts/mxn.cloudmade.core-min.js +15 -0
- data/vendor/assets/javascripts/mxn.cloudmade.core.js +383 -0
- data/vendor/assets/javascripts/mxn.core-min.js +15 -0
- data/vendor/assets/javascripts/mxn.core.js +1892 -0
- data/vendor/assets/javascripts/mxn.geocoder-min.js +15 -0
- data/vendor/assets/javascripts/mxn.geocoder.js +74 -0
- data/vendor/assets/javascripts/mxn.geocommons.core-min.js +15 -0
- data/vendor/assets/javascripts/mxn.geocommons.core.js +343 -0
- data/vendor/assets/javascripts/mxn.google.core-min.js +15 -0
- data/vendor/assets/javascripts/mxn.google.core.js +536 -0
- data/vendor/assets/javascripts/mxn.google.geocoder-min.js +15 -0
- data/vendor/assets/javascripts/mxn.google.geocoder.js +87 -0
- data/vendor/assets/javascripts/mxn.googleearth.core-min.js +15 -0
- data/vendor/assets/javascripts/mxn.googleearth.core.js +350 -0
- data/vendor/assets/javascripts/mxn.googlev3.core-min.js +15 -0
- data/vendor/assets/javascripts/mxn.googlev3.core.js +630 -0
- data/vendor/assets/javascripts/mxn.googlev3.geocoder-min.js +15 -0
- data/vendor/assets/javascripts/mxn.googlev3.geocoder.js +101 -0
- data/vendor/assets/javascripts/mxn.js +581 -0
- data/vendor/assets/javascripts/mxn.leaflet.core-min.js +15 -0
- data/vendor/assets/javascripts/mxn.leaflet.core.js +398 -0
- data/vendor/assets/javascripts/mxn.mapquest.geocoder-min.js +15 -0
- data/vendor/assets/javascripts/mxn.mapquest.geocoder.js +63 -0
- data/vendor/assets/javascripts/mxn.microsoft.core-min.js +15 -0
- data/vendor/assets/javascripts/mxn.microsoft.core.js +429 -0
- data/vendor/assets/javascripts/mxn.microsoft7.core-min.js +15 -0
- data/vendor/assets/javascripts/mxn.microsoft7.core.js +458 -0
- data/vendor/assets/javascripts/mxn.microsoft7.geocoder-min.js +15 -0
- data/vendor/assets/javascripts/mxn.microsoft7.geocoder.js +66 -0
- data/vendor/assets/javascripts/mxn.multimap.core-min.js +15 -0
- data/vendor/assets/javascripts/mxn.multimap.core.js +473 -0
- data/vendor/assets/javascripts/mxn.openlayers.core-min.js +15 -0
- data/vendor/assets/javascripts/mxn.openlayers.core.js +630 -0
- data/vendor/assets/javascripts/mxn.openlayers.geocoder-min.js +15 -0
- data/vendor/assets/javascripts/mxn.openlayers.geocoder.js +106 -0
- data/vendor/assets/javascripts/mxn.openmq.core-min.js +15 -0
- data/vendor/assets/javascripts/mxn.openmq.core.js +364 -0
- data/vendor/assets/javascripts/mxn.openspace.core-min.js +15 -0
- data/vendor/assets/javascripts/mxn.openspace.core.js +460 -0
- data/vendor/assets/javascripts/mxn.ovi.core-min.js +15 -0
- data/vendor/assets/javascripts/mxn.ovi.core.js +508 -0
- data/vendor/assets/javascripts/mxn.ovi.geocoder-min.js +15 -0
- data/vendor/assets/javascripts/mxn.ovi.geocoder.js +129 -0
- data/vendor/assets/javascripts/mxn.yahoo.core-min.js +15 -0
- data/vendor/assets/javascripts/mxn.yahoo.core.js +406 -0
- data/vendor/assets/javascripts/mxn.yandex.core-min.js +15 -0
- data/vendor/assets/javascripts/mxn.yandex.core.js +527 -0
- data/vendor/assets/javascripts/mxn.yandex.geocoder-min.js +15 -0
- data/vendor/assets/javascripts/mxn.yandex.geocoder.js +66 -0
- metadata +110 -0
@@ -0,0 +1,630 @@
|
|
1
|
+
/*
|
2
|
+
MAPSTRACTION v2.0.18 http://www.mapstraction.com
|
3
|
+
|
4
|
+
Copyright (c) 2012 Tom Carden, Steve Coast, Mikel Maron, Andrew Turner, Henri Bergius, Rob Moran, Derek Fowler, Gary Gale
|
5
|
+
All rights reserved.
|
6
|
+
|
7
|
+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
8
|
+
|
9
|
+
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
10
|
+
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
11
|
+
* Neither the name of the Mapstraction nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
12
|
+
|
13
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
14
|
+
*/
|
15
|
+
mxn.register('openlayers', {
|
16
|
+
|
17
|
+
Mapstraction: {
|
18
|
+
|
19
|
+
init: function(element, api){
|
20
|
+
var me = this;
|
21
|
+
|
22
|
+
var map = new OpenLayers.Map(
|
23
|
+
element.id,
|
24
|
+
{
|
25
|
+
maxExtent: new OpenLayers.Bounds(-20037508.34,-20037508.34,20037508.34,20037508.34),
|
26
|
+
maxResolution: 156543,
|
27
|
+
numZoomLevels: 18,
|
28
|
+
units: 'm',
|
29
|
+
projection: 'EPSG:900913'
|
30
|
+
}
|
31
|
+
);
|
32
|
+
|
33
|
+
// initialize layers map (this was previously in mxn.core.js)
|
34
|
+
this.layers = {};
|
35
|
+
|
36
|
+
this.layers.osm = new OpenLayers.Layer.TMS(
|
37
|
+
'OpenStreetMap',
|
38
|
+
[
|
39
|
+
"http://a.tile.openstreetmap.org/",
|
40
|
+
"http://b.tile.openstreetmap.org/",
|
41
|
+
"http://c.tile.openstreetmap.org/"
|
42
|
+
],
|
43
|
+
{
|
44
|
+
type:'png',
|
45
|
+
getURL: function (bounds) {
|
46
|
+
var res = this.map.getResolution();
|
47
|
+
var x = Math.round ((bounds.left - this.maxExtent.left) / (res * this.tileSize.w));
|
48
|
+
var y = Math.round ((this.maxExtent.top - bounds.top) / (res * this.tileSize.h));
|
49
|
+
var z = this.map.getZoom();
|
50
|
+
var limit = Math.pow(2, z);
|
51
|
+
if (y < 0 || y >= limit) {
|
52
|
+
return null;
|
53
|
+
} else {
|
54
|
+
x = ((x % limit) + limit) % limit;
|
55
|
+
var path = z + "/" + x + "/" + y + "." + this.type;
|
56
|
+
var url = this.url;
|
57
|
+
if (url instanceof Array) {
|
58
|
+
url = this.selectUrl(path, url);
|
59
|
+
}
|
60
|
+
return url + path;
|
61
|
+
}
|
62
|
+
},
|
63
|
+
displayOutsideMaxExtent: true
|
64
|
+
}
|
65
|
+
);
|
66
|
+
|
67
|
+
// deal with click
|
68
|
+
map.events.register('click', map, function(evt){
|
69
|
+
var lonlat = map.getLonLatFromViewPortPx(evt.xy);
|
70
|
+
var point = new mxn.LatLonPoint();
|
71
|
+
point.fromProprietary(api, lonlat);
|
72
|
+
me.click.fire({'location': point });
|
73
|
+
});
|
74
|
+
|
75
|
+
// deal with zoom change
|
76
|
+
map.events.register('zoomend', map, function(evt){
|
77
|
+
me.changeZoom.fire();
|
78
|
+
});
|
79
|
+
|
80
|
+
// deal with map movement
|
81
|
+
map.events.register('moveend', map, function(evt){
|
82
|
+
me.moveendHandler(me);
|
83
|
+
me.endPan.fire();
|
84
|
+
});
|
85
|
+
|
86
|
+
// deal with initial tile loading
|
87
|
+
var loadfire = function(e) {
|
88
|
+
me.load.fire();
|
89
|
+
this.events.unregister('loadend', this, loadfire);
|
90
|
+
};
|
91
|
+
|
92
|
+
for (var layerName in this.layers) {
|
93
|
+
if (this.layers.hasOwnProperty(layerName)) {
|
94
|
+
if (this.layers[layerName].visibility === true) {
|
95
|
+
this.layers[layerName].events.register('loadend', this.layers[layerName], loadfire);
|
96
|
+
}
|
97
|
+
}
|
98
|
+
}
|
99
|
+
|
100
|
+
map.addLayer(this.layers.osm);
|
101
|
+
this.tileLayers.push(["http://a.tile.openstreetmap.org/", this.layers.osm, true]);
|
102
|
+
this.maps[api] = map;
|
103
|
+
this.loaded[api] = true;
|
104
|
+
},
|
105
|
+
|
106
|
+
applyOptions: function(){
|
107
|
+
var map = this.maps[this.api],
|
108
|
+
navigators = map.getControlsByClass( 'OpenLayers.Control.Navigation' ),
|
109
|
+
navigator;
|
110
|
+
|
111
|
+
if ( navigators.length > 0 ) {
|
112
|
+
navigator = navigators[0];
|
113
|
+
if ( this.options.enableScrollWheelZoom ) {
|
114
|
+
navigator.enableZoomWheel();
|
115
|
+
} else {
|
116
|
+
navigator.disableZoomWheel();
|
117
|
+
}
|
118
|
+
if ( this.options.enableDragging ) {
|
119
|
+
navigator.activate();
|
120
|
+
} else {
|
121
|
+
navigator.deactivate();
|
122
|
+
}
|
123
|
+
}
|
124
|
+
},
|
125
|
+
|
126
|
+
resizeTo: function(width, height){
|
127
|
+
this.currentElement.style.width = width;
|
128
|
+
this.currentElement.style.height = height;
|
129
|
+
this.maps[this.api].updateSize();
|
130
|
+
},
|
131
|
+
|
132
|
+
addControls: function( args ) {
|
133
|
+
var map = this.maps[this.api];
|
134
|
+
// FIXME: OpenLayers has a bug removing all the controls says crschmidt
|
135
|
+
for (var i = map.controls.length; i>1; i--) {
|
136
|
+
map.controls[i-1].deactivate();
|
137
|
+
map.removeControl(map.controls[i-1]);
|
138
|
+
}
|
139
|
+
if ( args.zoom == 'large' ) {
|
140
|
+
map.addControl(new OpenLayers.Control.PanZoomBar());
|
141
|
+
}
|
142
|
+
else if ( args.zoom == 'small' ) {
|
143
|
+
map.addControl(new OpenLayers.Control.ZoomPanel());
|
144
|
+
if ( args.pan) {
|
145
|
+
map.addControl(new OpenLayers.Control.PanPanel());
|
146
|
+
}
|
147
|
+
}
|
148
|
+
else {
|
149
|
+
if ( args.pan){
|
150
|
+
map.addControl(new OpenLayers.Control.PanPanel());
|
151
|
+
}
|
152
|
+
}
|
153
|
+
if ( args.overview ) {
|
154
|
+
map.addControl(new OpenLayers.Control.OverviewMap());
|
155
|
+
}
|
156
|
+
if ( args.map_type ) {
|
157
|
+
map.addControl(new OpenLayers.Control.LayerSwitcher());
|
158
|
+
}
|
159
|
+
if ( args.scale ) {
|
160
|
+
map.addControl(new OpenLayers.Control.ScaleLine());
|
161
|
+
}
|
162
|
+
},
|
163
|
+
|
164
|
+
addSmallControls: function() {
|
165
|
+
var map = this.maps[this.api];
|
166
|
+
this.addControlsArgs.pan = false;
|
167
|
+
this.addControlsArgs.scale = false;
|
168
|
+
this.addControlsArgs.zoom = 'small';
|
169
|
+
map.addControl(new OpenLayers.Control.ZoomBox());
|
170
|
+
map.addControl(new OpenLayers.Control.LayerSwitcher({
|
171
|
+
'ascending':false
|
172
|
+
}));
|
173
|
+
},
|
174
|
+
|
175
|
+
addLargeControls: function() {
|
176
|
+
var map = this.maps[this.api];
|
177
|
+
map.addControl(new OpenLayers.Control.PanZoomBar());
|
178
|
+
this.addControlsArgs.pan = true;
|
179
|
+
this.addControlsArgs.zoom = 'large';
|
180
|
+
},
|
181
|
+
|
182
|
+
addMapTypeControls: function() {
|
183
|
+
var map = this.maps[this.api];
|
184
|
+
map.addControl( new OpenLayers.Control.LayerSwitcher({
|
185
|
+
'ascending':false
|
186
|
+
}) );
|
187
|
+
this.addControlsArgs.map_type = true;
|
188
|
+
},
|
189
|
+
|
190
|
+
setCenterAndZoom: function(point, zoom) {
|
191
|
+
var map = this.maps[this.api];
|
192
|
+
var pt = point.toProprietary(this.api);
|
193
|
+
map.setCenter(point.toProprietary(this.api), zoom);
|
194
|
+
},
|
195
|
+
|
196
|
+
addMarker: function(marker, old) {
|
197
|
+
var map = this.maps[this.api];
|
198
|
+
var pin = marker.toProprietary(this.api);
|
199
|
+
if (!this.layers.markers) {
|
200
|
+
this.layers.markers = new OpenLayers.Layer.Markers('markers');
|
201
|
+
map.addLayer(this.layers.markers);
|
202
|
+
}
|
203
|
+
this.layers.markers.addMarker(pin);
|
204
|
+
return pin;
|
205
|
+
},
|
206
|
+
|
207
|
+
removeMarker: function(marker) {
|
208
|
+
var map = this.maps[this.api];
|
209
|
+
var pin = marker.proprietary_marker;
|
210
|
+
this.layers.markers.removeMarker(pin);
|
211
|
+
pin.destroy();
|
212
|
+
},
|
213
|
+
|
214
|
+
declutterMarkers: function(opts) {
|
215
|
+
throw 'Not supported';
|
216
|
+
},
|
217
|
+
|
218
|
+
addPolyline: function(polyline, old) {
|
219
|
+
var map = this.maps[this.api];
|
220
|
+
var pl = polyline.toProprietary(this.api);
|
221
|
+
if (!this.layers.polylines) {
|
222
|
+
this.layers.polylines = new OpenLayers.Layer.Vector('polylines');
|
223
|
+
map.addLayer(this.layers.polylines);
|
224
|
+
}
|
225
|
+
this.layers.polylines.addFeatures([pl]);
|
226
|
+
return pl;
|
227
|
+
},
|
228
|
+
|
229
|
+
removePolyline: function(polyline) {
|
230
|
+
var map = this.maps[this.api];
|
231
|
+
var pl = polyline.proprietary_polyline;
|
232
|
+
this.layers.polylines.removeFeatures([pl]);
|
233
|
+
},
|
234
|
+
|
235
|
+
removeAllPolylines: function() {
|
236
|
+
var olpolylines = [];
|
237
|
+
for (var i = 0, length = this.polylines.length; i < length; i++) {
|
238
|
+
olpolylines.push(this.polylines[i].proprietary_polyline);
|
239
|
+
}
|
240
|
+
if (this.layers.polylines) {
|
241
|
+
this.layers.polylines.removeFeatures(olpolylines);
|
242
|
+
}
|
243
|
+
},
|
244
|
+
|
245
|
+
getCenter: function() {
|
246
|
+
var map = this.maps[this.api];
|
247
|
+
var pt = map.getCenter();
|
248
|
+
var mxnPt = new mxn.LatLonPoint();
|
249
|
+
mxnPt.fromProprietary(this.api, pt);
|
250
|
+
return mxnPt;
|
251
|
+
},
|
252
|
+
|
253
|
+
setCenter: function(point, options) {
|
254
|
+
var map = this.maps[this.api];
|
255
|
+
var pt = point.toProprietary(this.api);
|
256
|
+
map.setCenter(pt);
|
257
|
+
},
|
258
|
+
|
259
|
+
setZoom: function(zoom) {
|
260
|
+
var map = this.maps[this.api];
|
261
|
+
map.zoomTo(zoom);
|
262
|
+
},
|
263
|
+
|
264
|
+
getZoom: function() {
|
265
|
+
var map = this.maps[this.api];
|
266
|
+
return map.zoom;
|
267
|
+
},
|
268
|
+
|
269
|
+
getZoomLevelForBoundingBox: function( bbox ) {
|
270
|
+
var map = this.maps[this.api];
|
271
|
+
|
272
|
+
var sw = bbox.getSouthWest();
|
273
|
+
var ne = bbox.getNorthEast();
|
274
|
+
|
275
|
+
if(sw.lon > ne.lon) {
|
276
|
+
sw.lon -= 360;
|
277
|
+
}
|
278
|
+
|
279
|
+
var obounds = new OpenLayers.Bounds();
|
280
|
+
|
281
|
+
obounds.extend(new mxn.LatLonPoint(sw.lat,sw.lon).toProprietary(this.api));
|
282
|
+
obounds.extend(new mxn.LatLonPoint(ne.lat,ne.lon).toProprietary(this.api));
|
283
|
+
|
284
|
+
var zoom = map.getZoomForExtent(obounds);
|
285
|
+
|
286
|
+
return zoom;
|
287
|
+
},
|
288
|
+
|
289
|
+
setMapType: function(type) {
|
290
|
+
var map = this.maps[this.api];
|
291
|
+
throw 'Not implemented (setMapType)';
|
292
|
+
|
293
|
+
// switch(type) {
|
294
|
+
// case mxn.Mapstraction.ROAD:
|
295
|
+
// map.setMapTypeId(google.maps.MapTypeId.ROADMAP);
|
296
|
+
// break;
|
297
|
+
// case mxn.Mapstraction.SATELLITE:
|
298
|
+
// map.setMapTypeId(google.maps.MapTypeId.SATELLITE);
|
299
|
+
// break;
|
300
|
+
// case mxn.Mapstraction.HYBRID:
|
301
|
+
// map.setMapTypeId(google.maps.MapTypeId.HYBRID);
|
302
|
+
// break;
|
303
|
+
// default:
|
304
|
+
// map.setMapTypeId(google.maps.MapTypeId.ROADMAP);
|
305
|
+
// }
|
306
|
+
},
|
307
|
+
|
308
|
+
getMapType: function() {
|
309
|
+
var map = this.maps[this.api];
|
310
|
+
// TODO: implement actual layer support
|
311
|
+
return mxn.Mapstraction.ROAD;
|
312
|
+
|
313
|
+
// var type = map.getMapTypeId();
|
314
|
+
// switch(type) {
|
315
|
+
// case google.maps.MapTypeId.ROADMAP:
|
316
|
+
// return mxn.Mapstraction.ROAD;
|
317
|
+
// case google.maps.MapTypeId.SATELLITE:
|
318
|
+
// return mxn.Mapstraction.SATELLITE;
|
319
|
+
// case google.maps.MapTypeId.HYBRID:
|
320
|
+
// return mxn.Mapstraction.HYBRID;
|
321
|
+
// //case google.maps.MapTypeId.TERRAIN:
|
322
|
+
// // return something;
|
323
|
+
// default:
|
324
|
+
// return null;
|
325
|
+
// }
|
326
|
+
},
|
327
|
+
|
328
|
+
getBounds: function () {
|
329
|
+
var map = this.maps[this.api];
|
330
|
+
var olbox = map.calculateBounds();
|
331
|
+
var ol_sw = new OpenLayers.LonLat( olbox.left, olbox.bottom );
|
332
|
+
var mxn_sw = new mxn.LatLonPoint(0,0);
|
333
|
+
mxn_sw.fromProprietary( this.api, ol_sw );
|
334
|
+
var ol_ne = new OpenLayers.LonLat( olbox.right, olbox.top );
|
335
|
+
var mxn_ne = new mxn.LatLonPoint(0,0);
|
336
|
+
mxn_ne.fromProprietary( this.api, ol_ne );
|
337
|
+
return new mxn.BoundingBox(mxn_sw.lat, mxn_sw.lon, mxn_ne.lat, mxn_ne.lon);
|
338
|
+
},
|
339
|
+
|
340
|
+
setBounds: function(bounds){
|
341
|
+
var map = this.maps[this.api];
|
342
|
+
var sw = bounds.getSouthWest();
|
343
|
+
var ne = bounds.getNorthEast();
|
344
|
+
|
345
|
+
if(sw.lon > ne.lon) {
|
346
|
+
sw.lon -= 360;
|
347
|
+
}
|
348
|
+
|
349
|
+
var obounds = new OpenLayers.Bounds();
|
350
|
+
|
351
|
+
obounds.extend(new mxn.LatLonPoint(sw.lat,sw.lon).toProprietary(this.api));
|
352
|
+
obounds.extend(new mxn.LatLonPoint(ne.lat,ne.lon).toProprietary(this.api));
|
353
|
+
map.zoomToExtent(obounds);
|
354
|
+
},
|
355
|
+
|
356
|
+
addImageOverlay: function(id, src, opacity, west, south, east, north, oContext) {
|
357
|
+
var map = this.maps[this.api];
|
358
|
+
var bounds = new OpenLayers.Bounds();
|
359
|
+
bounds.extend(new mxn.LatLonPoint(south,west).toProprietary(this.api));
|
360
|
+
bounds.extend(new mxn.LatLonPoint(north,east).toProprietary(this.api));
|
361
|
+
var overlay = new OpenLayers.Layer.Image(
|
362
|
+
id,
|
363
|
+
src,
|
364
|
+
bounds,
|
365
|
+
new OpenLayers.Size(oContext.imgElm.width, oContext.imgElm.height),
|
366
|
+
{'isBaseLayer': false, 'alwaysInRange': true}
|
367
|
+
);
|
368
|
+
map.addLayer(overlay);
|
369
|
+
this.setImageOpacity(overlay.div.id, opacity);
|
370
|
+
},
|
371
|
+
|
372
|
+
setImagePosition: function(id, oContext) {
|
373
|
+
// do nothing
|
374
|
+
},
|
375
|
+
|
376
|
+
addOverlay: function(url, autoCenterAndZoom) {
|
377
|
+
var map = this.maps[this.api];
|
378
|
+
var kml = new OpenLayers.Layer.GML("kml", url,{
|
379
|
+
'format': OpenLayers.Format.KML,
|
380
|
+
'formatOptions': new OpenLayers.Format.KML({
|
381
|
+
'extractStyles': true,
|
382
|
+
'extractAttributes': true
|
383
|
+
}),
|
384
|
+
'projection': new OpenLayers.Projection('EPSG:4326')
|
385
|
+
});
|
386
|
+
if (autoCenterAndZoom) {
|
387
|
+
var setExtent = function() {
|
388
|
+
dataExtent = this.getDataExtent();
|
389
|
+
map.zoomToExtent(dataExtent);
|
390
|
+
};
|
391
|
+
kml.events.register('loadend', kml, setExtent);
|
392
|
+
}
|
393
|
+
map.addLayer(kml);
|
394
|
+
},
|
395
|
+
|
396
|
+
addTileLayer: function(tile_url, opacity, copyright_text, min_zoom, max_zoom, map_type) {
|
397
|
+
var map = this.maps[this.api];
|
398
|
+
var new_tile_url = tile_url.replace(/\{Z\}/g,'${z}');
|
399
|
+
new_tile_url = new_tile_url.replace(/\{X\}/g,'${x}');
|
400
|
+
new_tile_url = new_tile_url.replace(/\{Y\}/g,'${y}');
|
401
|
+
var overlay = new OpenLayers.Layer.XYZ(copyright_text,
|
402
|
+
new_tile_url,
|
403
|
+
{sphericalMercator: false, opacity: opacity}
|
404
|
+
);
|
405
|
+
if(!map_type) {
|
406
|
+
overlay.addOptions({displayInLayerSwitcher: false, isBaseLayer: false});
|
407
|
+
}
|
408
|
+
map.addLayer(overlay);
|
409
|
+
this.tileLayers.push( [tile_url, overlay, false] );
|
410
|
+
},
|
411
|
+
|
412
|
+
toggleTileLayer: function(tile_url) {
|
413
|
+
var map = this.maps[this.api];
|
414
|
+
for (var f=this.tileLayers.length-1; f>=0; f--) {
|
415
|
+
if(this.tileLayers[f][0] == tile_url) {
|
416
|
+
this.tileLayers[f][2] = !this.tileLayers[f][2];
|
417
|
+
this.tileLayers[f][1].setVisibility(this.tileLayers[f][2]);
|
418
|
+
}
|
419
|
+
}
|
420
|
+
// TODO: Add provider code
|
421
|
+
},
|
422
|
+
|
423
|
+
getPixelRatio: function() {
|
424
|
+
var map = this.maps[this.api];
|
425
|
+
|
426
|
+
// TODO: Add provider code
|
427
|
+
},
|
428
|
+
|
429
|
+
mousePosition: function(element) {
|
430
|
+
var map = this.maps[this.api];
|
431
|
+
var locDisp = document.getElementById(element);
|
432
|
+
if (locDisp !== null) {
|
433
|
+
map.events.register('mousemove', map, function (evt) {
|
434
|
+
var lonlat = map.getLonLatFromViewPortPx(evt.xy);
|
435
|
+
var point = new mxn.LatLonPoint();
|
436
|
+
point.fromProprietary('openlayers', lonlat);
|
437
|
+
var loc = point.lat.toFixed(4) + ' / ' + point.lon.toFixed(4);
|
438
|
+
locDisp.innerHTML = loc;
|
439
|
+
});
|
440
|
+
}
|
441
|
+
locDisp.innerHTML = '0.0000 / 0.0000';
|
442
|
+
}
|
443
|
+
},
|
444
|
+
|
445
|
+
LatLonPoint: {
|
446
|
+
|
447
|
+
toProprietary: function() {
|
448
|
+
var ollon = this.lon * 20037508.34 / 180;
|
449
|
+
var ollat = Math.log(Math.tan((90 + this.lat) * Math.PI / 360)) / (Math.PI / 180);
|
450
|
+
ollat = ollat * 20037508.34 / 180;
|
451
|
+
return new OpenLayers.LonLat(ollon, ollat);
|
452
|
+
},
|
453
|
+
|
454
|
+
fromProprietary: function(olPoint) {
|
455
|
+
var lon = (olPoint.lon / 20037508.34) * 180;
|
456
|
+
var lat = (olPoint.lat / 20037508.34) * 180;
|
457
|
+
lat = 180/Math.PI * (2 * Math.atan(Math.exp(lat * Math.PI / 180)) - Math.PI / 2);
|
458
|
+
this.lon = lon;
|
459
|
+
this.lat = lat;
|
460
|
+
}
|
461
|
+
|
462
|
+
},
|
463
|
+
|
464
|
+
Marker: {
|
465
|
+
|
466
|
+
toProprietary: function() {
|
467
|
+
var size, anchor, popup;
|
468
|
+
if(this.iconSize) {
|
469
|
+
size = new OpenLayers.Size(this.iconSize[0], this.iconSize[1]);
|
470
|
+
}
|
471
|
+
else {
|
472
|
+
size = new OpenLayers.Size(21,25);
|
473
|
+
}
|
474
|
+
|
475
|
+
if(this.iconAnchor) {
|
476
|
+
anchor = new OpenLayers.Pixel(-this.iconAnchor[0], -this.iconAnchor[1]);
|
477
|
+
}
|
478
|
+
else {
|
479
|
+
anchor = new OpenLayers.Pixel(-(size.w/2), -size.h);
|
480
|
+
}
|
481
|
+
|
482
|
+
if(this.iconUrl) {
|
483
|
+
this.icon = new OpenLayers.Icon(this.iconUrl, size, anchor);
|
484
|
+
}
|
485
|
+
else {
|
486
|
+
this.icon = new OpenLayers.Icon('http://openlayers.org/dev/img/marker-gold.png', size, anchor);
|
487
|
+
}
|
488
|
+
var marker = new OpenLayers.Marker(this.location.toProprietary("openlayers"), this.icon);
|
489
|
+
|
490
|
+
if(this.infoBubble) {
|
491
|
+
popup = new OpenLayers.Popup.FramedCloud(null,
|
492
|
+
this.location.toProprietary("openlayers"),
|
493
|
+
new OpenLayers.Size(100,100),
|
494
|
+
this.infoBubble,
|
495
|
+
this.icon,
|
496
|
+
true
|
497
|
+
);
|
498
|
+
var theMap = this.map;
|
499
|
+
if(this.hover) {
|
500
|
+
marker.events.register("mouseover", marker, function(event) {
|
501
|
+
theMap.addPopup(popup);
|
502
|
+
popup.show();
|
503
|
+
});
|
504
|
+
marker.events.register("mouseout", marker, function(event) {
|
505
|
+
popup.hide();
|
506
|
+
theMap.removePopup(popup);
|
507
|
+
});
|
508
|
+
}
|
509
|
+
else {
|
510
|
+
var shown = false;
|
511
|
+
marker.events.register("mousedown", marker, function(event) {
|
512
|
+
if (shown) {
|
513
|
+
popup.hide();
|
514
|
+
theMap.removePopup(popup);
|
515
|
+
shown = false;
|
516
|
+
} else {
|
517
|
+
theMap.addPopup(popup);
|
518
|
+
popup.show();
|
519
|
+
shown = true;
|
520
|
+
}
|
521
|
+
});
|
522
|
+
}
|
523
|
+
this.popup = popup;
|
524
|
+
}
|
525
|
+
|
526
|
+
//fire click event for marker
|
527
|
+
marker.events.register("click",marker,function(event) {
|
528
|
+
marker.mapstraction_marker.click.fire();
|
529
|
+
});
|
530
|
+
|
531
|
+
if(this.hoverIconUrl) {
|
532
|
+
icon = this.iconUrl || 'http://openlayers.org/dev/img/marker-gold.png';
|
533
|
+
hovericon = this.hoverIconUrl;
|
534
|
+
marker.events.register("mouseover", marker, function(event) {
|
535
|
+
marker.setUrl(hovericon);
|
536
|
+
});
|
537
|
+
marker.events.register("mouseout", marker, function(event) {
|
538
|
+
marker.setUrl(icon);
|
539
|
+
});
|
540
|
+
}
|
541
|
+
|
542
|
+
if(this.infoDiv){
|
543
|
+
// TODO
|
544
|
+
}
|
545
|
+
return marker;
|
546
|
+
},
|
547
|
+
|
548
|
+
openBubble: function() {
|
549
|
+
if ( this.infoBubble ) {
|
550
|
+
// Need to create a new popup in case setInfoBubble has been called
|
551
|
+
this.popup = new OpenLayers.Popup.FramedCloud(null,
|
552
|
+
this.location.toProprietary("openlayers"),
|
553
|
+
new OpenLayers.Size(100,100),
|
554
|
+
this.infoBubble,
|
555
|
+
this.icon,
|
556
|
+
true
|
557
|
+
);
|
558
|
+
}
|
559
|
+
|
560
|
+
if ( this.popup ) {
|
561
|
+
this.map.addPopup( this.popup, true );
|
562
|
+
}
|
563
|
+
},
|
564
|
+
|
565
|
+
closeBubble: function() {
|
566
|
+
if ( this.popup ) {
|
567
|
+
this.popup.hide();
|
568
|
+
this.map.removePopup( this.popup );
|
569
|
+
}
|
570
|
+
},
|
571
|
+
|
572
|
+
hide: function() {
|
573
|
+
this.proprietary_marker.display( false );
|
574
|
+
},
|
575
|
+
|
576
|
+
show: function() {
|
577
|
+
this.proprietary_marker.display( true );
|
578
|
+
},
|
579
|
+
|
580
|
+
update: function() {
|
581
|
+
// TODO: Add provider code
|
582
|
+
}
|
583
|
+
|
584
|
+
},
|
585
|
+
|
586
|
+
Polyline: {
|
587
|
+
|
588
|
+
toProprietary: function() {
|
589
|
+
var olpolyline;
|
590
|
+
var olpoints = [];
|
591
|
+
var ring;
|
592
|
+
var style = {
|
593
|
+
strokeColor: this.color || "#000000",
|
594
|
+
strokeOpacity: this.opacity || 1,
|
595
|
+
strokeWidth: this.width || 1,
|
596
|
+
fillColor: this.fillColor || "#000000",
|
597
|
+
fillOpacity: this.getAttribute('fillOpacity') || 0.2
|
598
|
+
};
|
599
|
+
|
600
|
+
//TODO Handle closed attribute
|
601
|
+
|
602
|
+
for (var i = 0, length = this.points.length ; i< length; i++){
|
603
|
+
olpoint = this.points[i].toProprietary("openlayers");
|
604
|
+
olpoints.push(new OpenLayers.Geometry.Point(olpoint.lon, olpoint.lat));
|
605
|
+
}
|
606
|
+
|
607
|
+
if (this.closed) {
|
608
|
+
// a closed polygon
|
609
|
+
ring = new OpenLayers.Geometry.LinearRing(olpoints);
|
610
|
+
} else {
|
611
|
+
// a line
|
612
|
+
ring = new OpenLayers.Geometry.LineString(olpoints);
|
613
|
+
}
|
614
|
+
|
615
|
+
olpolyline = new OpenLayers.Feature.Vector(ring, null, style);
|
616
|
+
|
617
|
+
return olpolyline;
|
618
|
+
},
|
619
|
+
|
620
|
+
show: function() {
|
621
|
+
throw 'Not implemented';
|
622
|
+
},
|
623
|
+
|
624
|
+
hide: function() {
|
625
|
+
throw 'Not implemented';
|
626
|
+
}
|
627
|
+
|
628
|
+
}
|
629
|
+
|
630
|
+
});
|
@@ -0,0 +1,15 @@
|
|
1
|
+
/*
|
2
|
+
MAPSTRACTION v2.0.18 http://www.mapstraction.com
|
3
|
+
|
4
|
+
Copyright (c) 2012 Tom Carden, Steve Coast, Mikel Maron, Andrew Turner, Henri Bergius, Rob Moran, Derek Fowler, Gary Gale
|
5
|
+
All rights reserved.
|
6
|
+
|
7
|
+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
8
|
+
|
9
|
+
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
10
|
+
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
11
|
+
* Neither the name of the Mapstraction nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
12
|
+
|
13
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
14
|
+
*/
|
15
|
+
mxn.register("openlayers",{Geocoder:{init:function(){var a=this},geocode:function(a){var c=this;if(!a.hasOwnProperty("address")||a.address===null||a.address===""){a.address=[a.street,a.locality,a.region,a.country].join(", ")}if(a.hasOwnProperty("lat")&&a.hasOwnProperty("lon")){var b=a.toProprietary(this.api);OpenLayers.Request.GET({url:"http://nominatim.openstreetmap.org/reverse",params:{lat:a.lat,lon:a.lon,addressdetails:1,format:"json"},callback:function(d){c.geocode_callback(JSON.parse(d.responseText),d.status)}})}else{OpenLayers.Request.GET({url:"http://nominatim.openstreetmap.org/search",params:{q:a.address,addressdetails:1,format:"json"},callback:function(d){c.geocode_callback(JSON.parse(d.responseText),d.status)}})}},geocode_callback:function(e,c){var a={};if(c!=200){this.error_callback(response.statusText)}else{a.street="";a.locality="";a.postcode="";a.region="";a.country="";var b;if(e.length>0){b=e[0]}else{b=e}var d=[];if(b.address.country){a.country=b.address.country}if(b.address.state){a.region=b.address.state}if(b.address.city){a.locality=b.address.city}if(b.address.postcode){a.postcode=b.address.postcode}if(b.address.road){d.push(b.address.road)}if(b.address.house_number){d.unshift(b.address.house_number)}if(a.street===""&&d.length>0){a.street=d.join(" ")}a.point=new mxn.LatLonPoint(parseFloat(b.lat),parseFloat(b.lon));this.callback(a)}}}});
|