Mapstraction : google v2 is deprecated. So we move to v2 with googlev3 and openlayers.

will be used by narativeweb individual maps. 
               The gramps maps use v1 for the moment : no more crosshair in v2, ...


svn: r15530
This commit is contained in:
Serge Noiraud 2010-06-05 09:16:20 +00:00
parent 2d2a9481bf
commit b70e874315
8 changed files with 4588 additions and 0 deletions

7
src/mapstraction/README Normal file
View File

@ -0,0 +1,7 @@
Information about our mapstraction :
home : http://www.mapstraction.com/
doc : http://www.mapstraction.com/doc/
svn : http://mapstraction.googlecode.com/svn/trunk
rev : 86
Mapstraction v2 API Sandbox : http://mapstraction.appspot.com/

1924
src/mapstraction/mxn.core.js Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,342 @@
/*
Copyright (c) 2010 Tom Carden, Steve Coast, Mikel Maron, Andrew Turner, Henri Bergius, Rob Moran, Derek Fowler
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* 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.
* 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.
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.
*/
mxn.register('geocommons', {
Mapstraction: {
// These methods can be called anytime but will only execute
// once the map has loaded.
deferrable: {
applyOptions: true,
resizeTo: true,
addControls: true,
addSmallControls: true,
addLargeControls: true,
addMapTypeControls: true,
dragging: true,
setCenterAndZoom: true,
getCenter: true,
setCenter: true,
setZoom: true,
getZoom: true,
getZoomLevelForBoundingBox: true,
setMapType: true,
getMapType: true,
getBounds: true,
setBounds: true,
addTileLayer: true,
toggleTileLayer: true,
getPixelRatio: true,
mousePosition: true
},
init: function(element, api) {
var me = this;
this.element = element;
this.loaded[this.api] = false; // Loading will take a little bit.
F1.Maker.core_host = f1_core_host;
F1.Maker.finder_host = f1_finder_host;
F1.Maker.maker_host = f1_maker_host;
// we don't use this object but assign it to dummy for JSLint
var dummy = new F1.Maker.Map({
dom_id: this.element.id,
flashvars: {},
onload: function(map){
me.maps[me.api] = map.swf; // Get the actual Flash object
me.loaded[me.api] = true;
for (var i = 0; i < me.onload[me.api].length; i++) {
me.onload[me.api][i]();
}
}
});
},
applyOptions: function(){
var map = this.maps[this.api];
// TODO: Add provider code
},
resizeTo: function(width, height){
var map = this.maps[this.api];
map.setSize(width,height);
},
addControls: function( args ) {
var map = this.maps[this.api];
map.showControl("Zoom", args.zoom || false);
map.showControl("Layers", args.layers || false);
map.showControl("Styles", args.styles || false);
map.showControl("Basemap", args.map_type || false);
map.showControl("Legend", args.legend || false, "open");
// showControl("Legend", true, "close");
},
addSmallControls: function() {
var map = this.maps[this.api];
this.addControls({
zoom: 'small',
legend: "open"
});
// showControl("Zoom", args.zoom);
// showControl("Legend", args.legend, "open");
},
addLargeControls: function() {
var map = this.maps[this.api];
this.addControls({
zoom: 'large',
layers: true,
legend: "open"
});
},
addMapTypeControls: function() {
var map = this.maps[this.api];
// TODO: Add provider code
},
dragging: function(on) {
var map = this.maps[this.api];
// TODO: Add provider code
},
setCenterAndZoom: function(point, zoom) {
var map = this.maps[this.api];
map.setCenterZoom(point.lat, point.lon,zoom);
},
getCenter: function() {
var map = this.maps[this.api];
var point = map.getCenterZoom()[0];
return new mxn.LatLonPoint(point.lat,point.lon);
},
setCenter: function(point, options) {
var map = this.maps[this.api];
map.setCenter(point.lat, point.lon);
},
setZoom: function(zoom) {
var map = this.maps[this.api];
map.setZoom(zoom);
},
getZoom: function() {
var map = this.maps[this.api];
return map.getZoom();
},
getZoomLevelForBoundingBox: function( bbox ) {
var map = this.maps[this.api];
// NE and SW points from the bounding box.
var ne = bbox.getNorthEast();
var sw = bbox.getSouthWest();
var zoom;
// TODO: Add provider code
return zoom;
},
setMapType: function(type) {
var map = this.maps[this.api];
switch(type) {
case mxn.Mapstraction.ROAD:
map.setMapProvider("OpenStreetMap (road)");
break;
case mxn.Mapstraction.SATELLITE:
map.setMapProvider("BlueMarble");
break;
case mxn.Mapstraction.HYBRID:
map.setMapProvider("Google Hybrid");
break;
default:
map.setMapProvider(type);
}
},
getMapType: function() {
var map = this.maps[this.api];
// TODO: I don't thick this is correct -Derek
switch(map.getMapProvider()) {
case "OpenStreetMap (road)":
return mxn.Mapstraction.ROAD;
case "BlueMarble":
return mxn.Mapstraction.SATELLITE;
case "Google Hybrid":
return mxn.Mapstraction.HYBRID;
default:
return null;
}
},
getBounds: function () {
var map = this.maps[this.api];
var extent = map.getExtent();
return new mxn.BoundingBox( extent.northWest.lat, extent.southEast.lon, extent.southEast.lat, extent.northWest.lon);
},
setBounds: function(bounds){
var map = this.maps[this.api];
var sw = bounds.getSouthWest();
var ne = bounds.getNorthEast();
map.setExtent(ne.lat,sw.lat,ne.lon,sw.lon);
},
addImageOverlay: function(id, src, opacity, west, south, east, north, oContext) {
var map = this.maps[this.api];
// TODO: Add provider code
},
// URL in this case is either a Maker map ID or the full URL to the Maker Map
addOverlay: function(url, autoCenterAndZoom) {
var map = this.maps[this.api];
var match;
if(typeof(url) === "number") {
map.loadMap(url);
return;
}
// Try if we've been given either a string of the ID or a URL
match = url.match(/^(\d+)$/);
if(match !== null){
match = url.match(/^.*?maps\/(\d+)(\?\(\[?(.*?)\]?\))?$/);
}
map.loadMap(match[1]);
},
addTileLayer: function(tile_url, opacity, copyright_text, min_zoom, max_zoom) {
var map = this.maps[this.api];
// TODO: Add provider code
},
toggleTileLayer: function(tile_url) {
var map = this.maps[this.api];
// TODO: Add provider code
},
getPixelRatio: function() {
var map = this.maps[this.api];
// TODO: Add provider code
},
mousePosition: function(element) {
var map = this.maps[this.api];
// TODO: Add provider code
},
addMarker: function(marker, old) {
var map = this.maps[this.api];
var pin = marker.toProprietary(this.api);
// TODO: Add provider code
// map.addOverlay(pin);
return pin;
},
removeMarker: function(marker) {
var map = this.maps[this.api];
// TODO: Add provider code
},
declutterMarkers: function(opts) {
var map = this.maps[this.api];
// TODO: Add provider code
},
addPolyline: function(polyline, old) {
var map = this.maps[this.api];
var pl = polyline.toProprietary(this.api);
// TODO: Add provider code
// map.addOverlay(pl);
return pl;
},
removePolyline: function(polyline) {
var map = this.maps[this.api];
// TODO: Add provider code
}
},
LatLonPoint: {
toProprietary: function() {
// TODO: Add provider code
return {};
},
fromProprietary: function(googlePoint) {
// TODO: Add provider code
}
},
Marker: {
toProprietary: function() {
// TODO: Add provider code
return {};
},
openBubble: function() {
// TODO: Add provider code
},
hide: function() {
// TODO: Add provider code
},
show: function() {
// TODO: Add provider code
},
update: function() {
// TODO: Add provider code
}
},
Polyline: {
toProprietary: function() {
return {};
// TODO: Add provider code
},
show: function() {
// TODO: Add provider code
},
hide: function() {
// TODO: Add provider code
}
}
});

View File

@ -0,0 +1,531 @@
/*
Copyright (c) 2010 Tom Carden, Steve Coast, Mikel Maron, Andrew Turner, Henri Bergius, Rob Moran, Derek Fowler
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* 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.
* 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.
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.
*/
mxn.register('google', {
Mapstraction: {
init: function(element,api) {
var me = this;
if (GMap2) {
if (GBrowserIsCompatible()) {
this.maps[api] = new GMap2(element);
GEvent.addListener(this.maps[api], 'click', function(marker,location) {
if ( marker && marker.mapstraction_marker ) {
marker.mapstraction_marker.click.fire();
}
else if ( location ) {
me.click.fire({'location': new mxn.LatLonPoint(location.y, location.x)});
}
// If the user puts their own Google markers directly on the map
// then there is no location and this event should not fire.
if ( location ) {
me.clickHandler(location.y,location.x,location,me);
}
});
GEvent.addListener(this.maps[api], 'moveend', function() {
me.moveendHandler(me);
me.endPan.fire();
});
GEvent.addListener(this.maps[api], 'zoomend', function() {
me.changeZoom.fire();
});
this.loaded[api] = true;
me.load.fire();
}
else {
alert('browser not compatible with Google Maps');
}
}
else {
alert(api + ' map script not imported');
}
},
applyOptions: function(){
var map = this.maps[this.api];
if(this.options.enableScrollWheelZoom){
map.enableContinuousZoom();
map.enableScrollWheelZoom();
}
if (this.options.enableDragging) {
map.enableDragging();
} else {
map.disableDragging();
}
},
resizeTo: function(width, height){
this.currentElement.style.width = width;
this.currentElement.style.height = height;
this.maps[this.api].checkResize();
},
addControls: function( args ) {
var map = this.maps[this.api];
// remove old controls
if (this.controls) {
while ((ctl = this.controls.pop())) {
// Google specific method
map.removeControl(ctl);
}
}
else {
this.controls = [];
}
c = this.controls;
// Google has a combined zoom and pan control.
if (args.zoom || args.pan) {
if (args.zoom == 'large'){
this.addLargeControls();
} else {
this.addSmallControls();
}
}
if (args.scale) {
this.controls.unshift(new GScaleControl());
map.addControl(this.controls[0]);
this.addControlsArgs.scale = true;
}
if (args.overview) {
c.unshift(new GOverviewMapControl());
map.addControl(c[0]);
this.addControlsArgs.overview = true;
}
if (args.map_type) {
this.addMapTypeControls();
}
},
addSmallControls: function() {
var map = this.maps[this.api];
this.controls.unshift(new GSmallMapControl());
map.addControl(this.controls[0]);
this.addControlsArgs.zoom = 'small';
this.addControlsArgs.pan = true;
},
addLargeControls: function() {
var map = this.maps[this.api];
this.controls.unshift(new GLargeMapControl());
map.addControl(this.controls[0]);
this.addControlsArgs.zoom = 'large';
this.addControlsArgs.pan = true;
},
addMapTypeControls: function() {
var map = this.maps[this.api];
this.controls.unshift(new GMapTypeControl());
map.addControl(this.controls[0]);
this.addControlsArgs.map_type = true;
},
setCenterAndZoom: function(point, zoom) {
var map = this.maps[this.api];
var pt = point.toProprietary(this.api);
map.setCenter(pt, zoom);
},
addMarker: function(marker, old) {
var map = this.maps[this.api];
var gpin = marker.toProprietary(this.api);
map.addOverlay(gpin);
GEvent.addListener(gpin, 'infowindowopen', function() {
marker.openInfoBubble.fire();
});
GEvent.addListener(gpin, 'infowindowclose', function() {
marker.closeInfoBubble.fire();
});
return gpin;
},
removeMarker: function(marker) {
var map = this.maps[this.api];
map.removeOverlay(marker.proprietary_marker);
},
declutterMarkers: function(opts) {
throw 'Not supported';
},
addPolyline: function(polyline, old) {
var map = this.maps[this.api];
gpolyline = polyline.toProprietary(this.api);
map.addOverlay(gpolyline);
return gpolyline;
},
removePolyline: function(polyline) {
var map = this.maps[this.api];
map.removeOverlay(polyline.proprietary_polyline);
},
getCenter: function() {
var map = this.maps[this.api];
var pt = map.getCenter();
var point = new mxn.LatLonPoint(pt.lat(),pt.lng());
return point;
},
setCenter: function(point, options) {
var map = this.maps[this.api];
var pt = point.toProprietary(this.api);
if(options && options.pan) {
map.panTo(pt);
}
else {
map.setCenter(pt);
}
},
setZoom: function(zoom) {
var map = this.maps[this.api];
map.setZoom(zoom);
},
getZoom: function() {
var map = this.maps[this.api];
return map.getZoom();
},
getZoomLevelForBoundingBox: function( bbox ) {
var map = this.maps[this.api];
// NE and SW points from the bounding box.
var ne = bbox.getNorthEast();
var sw = bbox.getSouthWest();
var gbox = new GLatLngBounds( sw.toProprietary(this.api), ne.toProprietary(this.api) );
var zoom = map.getBoundsZoomLevel( gbox );
return zoom;
},
setMapType: function(type) {
var map = this.maps[this.api];
switch(type) {
case mxn.Mapstraction.ROAD:
map.setMapType(G_NORMAL_MAP);
break;
case mxn.Mapstraction.SATELLITE:
map.setMapType(G_SATELLITE_MAP);
break;
case mxn.Mapstraction.HYBRID:
map.setMapType(G_HYBRID_MAP);
break;
case mxn.Mapstraction.PHYSICAL:
map.setMapType(G_PHYSICAL_MAP);
break;
default:
map.setMapType(type || G_NORMAL_MAP);
}
},
getMapType: function() {
var map = this.maps[this.api];
var type = map.getCurrentMapType();
switch(type) {
case G_NORMAL_MAP:
return mxn.Mapstraction.ROAD;
case G_SATELLITE_MAP:
return mxn.Mapstraction.SATELLITE;
case G_HYBRID_MAP:
return mxn.Mapstraction.HYBRID;
case G_PHYSICAL_MAP:
return mxn.Mapstraction.PHYSICAL;
default:
return null;
}
},
getBounds: function () {
var map = this.maps[this.api];
var ne, sw, nw, se;
var gbox = map.getBounds();
sw = gbox.getSouthWest();
ne = gbox.getNorthEast();
return new mxn.BoundingBox(sw.lat(), sw.lng(), ne.lat(), ne.lng());
},
setBounds: function(bounds){
var map = this.maps[this.api];
var sw = bounds.getSouthWest();
var ne = bounds.getNorthEast();
var gbounds = new GLatLngBounds(new GLatLng(sw.lat,sw.lon),new GLatLng(ne.lat,ne.lon));
map.setCenter(gbounds.getCenter(), map.getBoundsZoomLevel(gbounds));
},
addImageOverlay: function(id, src, opacity, west, south, east, north, oContext) {
var map = this.maps[this.api];
map.getPane(G_MAP_MAP_PANE).appendChild(oContext.imgElm);
this.setImageOpacity(id, opacity);
this.setImagePosition(id);
GEvent.bind(map, "zoomend", this, function() {
this.setImagePosition(id);
});
GEvent.bind(map, "moveend", this, function() {
this.setImagePosition(id);
});
},
setImagePosition: function(id, oContext) {
var map = this.maps[this.api];
var topLeftPoint; var bottomRightPoint;
topLeftPoint = map.fromLatLngToDivPixel( new GLatLng(oContext.latLng.top, oContext.latLng.left) );
bottomRightPoint = map.fromLatLngToDivPixel( new GLatLng(oContext.latLng.bottom, oContext.latLng.right) );
oContext.pixels.top = topLeftPoint.y;
oContext.pixels.left = topLeftPoint.x;
oContext.pixels.bottom = bottomRightPoint.y;
oContext.pixels.right = bottomRightPoint.x;
},
addOverlay: function(url, autoCenterAndZoom) {
var map = this.maps[this.api];
var geoXML = new GGeoXml(url);
map.addOverlay(geoXML, function() {
if(autoCenterAndZoom) {
geoXML.gotoDefaultViewport(map);
}
});
},
addTileLayer: function(tile_url, opacity, copyright_text, min_zoom, max_zoom, map_type) {
var copyright = new GCopyright(1, new GLatLngBounds(new GLatLng(-90,-180), new GLatLng(90,180)), 0, "copyleft");
var copyrightCollection = new GCopyrightCollection(copyright_text);
copyrightCollection.addCopyright(copyright);
var tilelayers = [];
tilelayers[0] = new GTileLayer(copyrightCollection, min_zoom, max_zoom);
tilelayers[0].isPng = function() {
return true;
};
tilelayers[0].getOpacity = function() {
return opacity;
};
tilelayers[0].getTileUrl = function (a, b) {
url = tile_url;
url = url.replace(/\{Z\}/g,b);
url = url.replace(/\{X\}/g,a.x);
url = url.replace(/\{Y\}/g,a.y);
return url;
};
if(map_type) {
var tileLayerOverlay = new GMapType(tilelayers, new GMercatorProjection(19), copyright_text, {
errorMessage:"More "+copyright_text+" tiles coming soon"
});
this.maps[this.api].addMapType(tileLayerOverlay);
} else {
tileLayerOverlay = new GTileLayerOverlay(tilelayers[0]);
this.maps[this.api].addOverlay(tileLayerOverlay);
}
this.tileLayers.push( [tile_url, tileLayerOverlay, true] );
return tileLayerOverlay;
},
toggleTileLayer: function(tile_url) {
for (var f=0; f<this.tileLayers.length; f++) {
if(this.tileLayers[f][0] == tile_url) {
if(this.tileLayers[f][2]) {
this.maps[this.api].removeOverlay(this.tileLayers[f][1]);
this.tileLayers[f][2] = false;
}
else {
this.maps[this.api].addOverlay(this.tileLayers[f][1]);
this.tileLayers[f][2] = true;
}
}
}
},
getPixelRatio: function() {
var map = this.maps[this.api];
var projection = G_NORMAL_MAP.getProjection();
var centerPoint = map.getCenter();
var zoom = map.getZoom();
var centerPixel = projection.fromLatLngToPixel(centerPoint, zoom);
// distance is the distance in metres for 5 pixels (3-4-5 triangle)
var distancePoint = projection.fromPixelToLatLng(new GPoint(centerPixel.x + 3, centerPixel.y + 4), zoom);
//*1000(km to m), /5 (pythag), *2 (radius to diameter)
return 10000/distancePoint.distanceFrom(centerPoint);
},
mousePosition: function(element) {
var locDisp = document.getElementById(element);
if (locDisp !== null) {
var map = this.maps[this.api];
GEvent.addListener(map, 'mousemove', function (point) {
var loc = point.lat().toFixed(4) + ' / ' + point.lng().toFixed(4);
locDisp.innerHTML = loc;
});
locDisp.innerHTML = '0.0000 / 0.0000';
}
}
},
LatLonPoint: {
toProprietary: function() {
return new GLatLng(this.lat,this.lon);
},
fromProprietary: function(googlePoint) {
this.lat = googlePoint.lat();
this.lon = googlePoint.lng();
}
},
Marker: {
toProprietary: function() {
var infoBubble, event_action, infoDiv, div;
var options = {};
if(this.labelText){
options.title = this.labelText;
}
if(this.iconUrl){
var icon = new GIcon(G_DEFAULT_ICON, this.iconUrl);
icon.printImage = icon.mozPrintImage = icon.image;
if(this.iconSize) {
icon.iconSize = new GSize(this.iconSize[0], this.iconSize[1]);
var anchor;
if(this.iconAnchor) {
anchor = new GPoint(this.iconAnchor[0], this.iconAnchor[1]);
}
else {
// FIXME: hard-coding the anchor point
anchor = new GPoint(this.iconSize[0]/2, this.iconSize[1]/2);
}
icon.iconAnchor = anchor;
}
if(typeof(this.iconShadowUrl) != 'undefined') {
icon.shadow = this.iconShadowUrl;
if(this.iconShadowSize) {
icon.shadowSize = new GSize(this.iconShadowSize[0], this.iconShadowSize[1]);
}
} else { // turn off shadow
icon.shadow = '';
icon.shadowSize = '';
}
if(this.transparent) {
icon.transparent = this.transparent;
}
if(this.imageMap) {
icon.imageMap = this.imageMap;
}
options.icon = icon;
}
if(this.draggable){
options.draggable = this.draggable;
}
var gmarker = new GMarker( this.location.toProprietary('google'),options);
if(this.infoBubble){
infoBubble = this.infoBubble;
if(this.hover) {
event_action = "mouseover";
}
else {
event_action = "click";
}
GEvent.addListener(gmarker, event_action, function() {
gmarker.openInfoWindowHtml(infoBubble, {
maxWidth: 100
});
});
}
if(this.hoverIconUrl){
GEvent.addListener(gmarker, "mouseover", function() {
gmarker.setImage(this.hoverIconUrl);
});
GEvent.addListener(gmarker, "mouseout", function() {
gmarker.setImage(this.iconUrl);
});
}
if(this.infoDiv){
infoDiv = this.infoDiv;
div = this.div;
if(this.hover) {
event_action = "mouseover";
}
else {
event_action = "click";
}
GEvent.addListener(gmarker, event_action, function() {
document.getElementById(div).innerHTML = infoDiv;
});
}
return gmarker;
},
openBubble: function() {
var gpin = this.proprietary_marker;
gpin.openInfoWindowHtml(this.infoBubble);
},
hide: function() {
this.proprietary_marker.hide();
},
show: function() {
this.proprietary_marker.show();
},
update: function() {
point = new mxn.LatLonPoint();
point.fromProprietary('google', this.proprietary_marker.getPoint());
this.location = point;
}
},
Polyline: {
toProprietary: function() {
var gpoints = [];
for (var i = 0, length = this.points.length ; i< length; i++){
gpoints.push(this.points[i].toProprietary('google'));
}
if (this.closed || gpoints[0].equals(gpoints[length-1])) {
return new GPolygon(gpoints, this.color, this.width, this.opacity, this.fillColor || "#5462E3", this.opacity || "0.3");
} else {
return new GPolyline(gpoints, this.color, this.width, this.opacity);
}
},
show: function() {
throw 'Not implemented';
},
hide: function() {
throw 'Not implemented';
}
}
});

View File

@ -0,0 +1,191 @@
/*
Copyright (c) 2010 Tom Carden, Steve Coast, Mikel Maron, Andrew Turner, Henri Bergius, Rob Moran, Derek Fowler
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* 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.
* 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.
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.
*/
/*
Copyright (c) 2007, Andrew Turner
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* 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.
* 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.
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.
*/
// Use http://jsdoc.sourceforge.net/ to generate documentation
// TODO: add reverse geocoding support
/**
* MapstractionGeocoder instantiates a geocoder with some API choice
* @param {Function} callback The function to call when a geocode request returns (function(waypoint))
* @param {String} api The API to use, currently only 'mapquest' is supported
* @param {Function} error_callback The optional function to call when a geocode request fails
* @constructor
*/
function MapstractionGeocoder(callback, api, error_callback) {
this.api = api;
this.callback = callback;
this.geocoders = {};
if(error_callback === null) {
this.error_callback = this.geocode_error;
} else {
this.error_callback = error_callback;
}
// This is so that it is easy to tell which revision of this file
// has been copied into other projects.
this.svn_revision_string = '$Revision: 107 $';
this.addAPI(api);
}
/**
* Internal function to actually set the router specific parameters
*/
MapstractionGeocoder.prototype.addAPI = function(api) {
me = this;
switch (api) {
case 'google':
this.geocoders[api] = new GClientGeocoder();
break;
case 'mapquest':
//set up the connection to the geocode server
var proxyServerName = "";
var proxyServerPort = "";
var ProxyServerPath = "mapquest_proxy/JSReqHandler.php";
var serverName = "geocode.access.mapquest.com";
var serverPort = "80";
var serverPath = "mq";
this.geocoders[api] = new MQExec(serverName, serverPath, serverPort, proxyServerName, ProxyServerPath, proxyServerPort );
break;
default:
alert(api + ' not supported by mapstraction-geocoder');
}
};
/**
* Change the Routing API to use
* @param {String} api The API to swap to
*/
MapstractionGeocoder.prototype.swap = function(api) {
if (this.api == api) { return; }
this.api = api;
if (!this.geocoders.hasOwnProperty(this.api)) {
this.addAPI($(element),api);
}
};
/**
* Default Geocode error function
*/
MapstractionGeocoder.prototype.geocode_error = function(response) {
alert("Sorry, we were unable to geocode that address");
};
/**
* Default handler for geocode request completion
*/
MapstractionGeocoder.prototype.geocode_callback = function(response, mapstraction_geocoder) {
var return_location = {};
// TODO: what if the api is switched during a geocode request?
// TODO: provide an option error callback
switch (mapstraction_geocoder.api) {
case 'google':
if (!response || response.Status.code != 200) {
mapstraction_geocoder.error_callback(response);
} else {
return_location.street = "";
return_location.locality = "";
return_location.region = "";
return_location.country = "";
var place = response.Placemark[0];
if(place.AddressDetails.Country.AdministrativeArea !== null) {
return_location.region = place.AddressDetails.Country.AdministrativeArea.AdministrativeAreaName;
if(place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea !== null) {
if(place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality !== null) {
return_location.locality = place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality.LocalityName;
if(place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality.Thoroughfare !== null) {
return_location.street = place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality.Thoroughfare.ThoroughfareName;
}
}
}
}
return_location.country = place.AddressDetails.Country.CountryNameCode;
return_location.address = place.address;
return_location.point = new mxn.LatLonPoint(place.Point.coordinates[1], place.Point.coordinates[0]);
mapstraction_geocoder.callback(return_location);
}
break;
case 'mapquest':
break;
}
};
/**
* Performs a geocoding and then calls the specified callback function with the location
* @param {Object} address The address object to geocode
*/
MapstractionGeocoder.prototype.geocode = function(address) {
var return_location = {};
// temporary variable for later using in function closure
var mapstraction_geocoder = this;
switch (this.api) {
case 'google':
if (address.address === null || address.address === "") {
address.address = address.street + ", " + address.locality + ", " + address.region + ", " + address.country;
}
this.geocoders[this.api].getLocations(address.address, function(response) { mapstraction_geocoder.geocode_callback(response, mapstraction_geocoder); });
break;
case 'mapquest':
var mqaddress = new MQAddress();
var gaCollection = new MQLocationCollection("MQGeoAddress");
//populate the address object with the information from the form
mqaddress.setStreet(address.street);
mqaddress.setCity(address.locality);
mqaddress.setState(address.region);
mqaddress.setPostalCode(address.postalcode);
mqaddress.setCountry(address.country);
this.geocoders[this.api].geocode(mqaddress, gaCollection);
var geoAddr = gaCollection.get(0);
var mqpoint = geoAddr.getMQLatLng();
return_location.street = geoAddr.getStreet();
return_location.locality = geoAddr.getCity();
return_location.region = geoAddr.getState();
return_location.country = geoAddr.getCountry();
return_location.point = new mxn.LatLonPoint(mqpoint.getLatitude(), mqpoint.getLongitude());
this.callback(return_location, this);
break;
default:
alert(api + ' not supported by mapstraction-geocoder');
break;
}
};

View File

@ -0,0 +1,505 @@
/*
Copyright (c) 2010 Tom Carden, Steve Coast, Mikel Maron, Andrew Turner, Henri Bergius, Rob Moran, Derek Fowler
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* 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.
* 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.
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.
*/
mxn.register('googlev3', {
Mapstraction: {
init: function(element, api){
var me = this;
if ( google && google.maps ){
// by default add road map and no controls
var myOptions = {
disableDefaultUI: true,
mapTypeId: google.maps.MapTypeId.ROADMAP,
mapTypeControl: false,
mapTypeControlOptions: null,
navigationControl: false,
navigationControlOptions: null,
scrollwheel: false
};
// find controls
if (!this.addControlsArgs && loadoptions.addControlsArgs) {
this.addControlsArgs = loadoptions.addControlsArgs;
}
if (this.addControlsArgs) {
if (this.addControlsArgs.zoom) {
myOptions.navigationControl = true;
if (this.addControlsArgs.zoom == 'small') {
myOptions.navigationControlOptions = {style: google.maps.NavigationControlStyle.SMALL};
}
if (this.addControlsArgs.zoom == 'large') {
myOptions.navigationControlOptions = {style: google.maps.NavigationControlStyle.ZOOM_PAN};
}
}
if (this.addControlsArgs.map_type) {
myOptions.mapTypeControl = true;
myOptions.mapTypeControlOptions = {style: google.maps.MapTypeControlStyle.DEFAULT};
}
}
var map = new google.maps.Map(element, myOptions);
// deal with click
google.maps.event.addListener(map, 'click', function(location){
me.click.fire({'location':
new mxn.LatLonPoint(location.latLng.lat(),location.latLng.lng())
});
});
// deal with zoom change
google.maps.event.addListener(map, 'zoom_changed', function(){
me.changeZoom.fire();
});
// deal with map movement
google.maps.event.addListener(map, 'dragend', function(){
me.moveendHandler(me);
me.endPan.fire();
});
this.maps[api] = map;
this.loaded[api] = true;
me.load.fire();
}
else {
alert(api + ' map script not imported');
}
},
applyOptions: function(){
var map = this.maps[this.api];
var myOptions = [];
if (this.options.enableDragging) {
myOptions.draggable = true;
}
if (this.options.enableScrollWheelZoom){
myOptions.scrollwheel = true;
}
map.setOptions(myOptions);
},
resizeTo: function(width, height){
this.currentElement.style.width = width;
this.currentElement.style.height = height;
var map = this.maps[this.api];
google.maps.event.trigger(map,'resize');
},
addControls: function( args ) {
var map = this.maps[this.api];
// remove old controls
// Google has a combined zoom and pan control.
if (args.zoom || args.pan) {
if (args.zoom == 'large'){
this.addLargeControls();
} else {
this.addSmallControls();
}
}
if (args.scale){
var myOptions = {
scaleControl:true,
scaleControlOptions: {style:google.maps.ScaleControlStyle.DEFAULT}
};
map.setOptions(myOptions);
this.addControlsArgs.scale = true;
}
if (args.map_type){
this.addMapTypeControls();
}
},
addSmallControls: function() {
var map = this.maps[this.api];
var myOptions = {
navigationControl: true,
navigationControlOptions: {style: google.maps.NavigationControlStyle.SMALL}
};
map.setOptions(myOptions);
this.addControlsArgs.pan = false;
this.addControlsArgs.scale = false;
this.addControlsArgs.zoom = 'small';
},
addLargeControls: function() {
var map = this.maps[this.api];
var myOptions = {
navigationControl: true,
navigationControlOptions: {style:google.maps.NavigationControlStyle.DEFAULT}
};
map.setOptions(myOptions);
this.addControlsArgs.pan = true;
this.addControlsArgs.zoom = 'large';
},
addMapTypeControls: function() {
var map = this.maps[this.api];
var myOptions = {
mapTypeControl: true,
mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DEFAULT}
};
map.setOptions(myOptions);
this.addControlsArgs.map_type = true;
},
setCenterAndZoom: function(point, zoom) {
var map = this.maps[this.api];
var pt = point.toProprietary(this.api);
map.setCenter(pt);
map.setZoom(zoom);
},
addMarker: function(marker, old) {
return marker.toProprietary(this.api);
},
removeMarker: function(marker) {
// doesn't really remove them, just hides them
marker.hide();
},
declutterMarkers: function(opts) {
var map = this.maps[this.api];
// TODO: Add provider code
},
addPolyline: function(polyline, old) {
var map = this.maps[this.api];
var gpoly = polyline.toProprietary(this.api);
gpoly.setMap(map);
return gpoly;
},
removePolyline: function(polyline) {
var map = this.maps[this.api];
polyline.proprietary_polyline.setMap(null);
},
getCenter: function() {
var map = this.maps[this.api];
var pt = map.getCenter();
return new mxn.LatLonPoint(pt.lat(),pt.lng());
},
setCenter: function(point, options) {
var map = this.maps[this.api];
var pt = point.toProprietary(this.api);
if(options && options.pan) {
map.panTo(pt);
}
else {
map.setCenter(pt);
}
},
setZoom: function(zoom) {
var map = this.maps[this.api];
map.setZoom(zoom);
},
getZoom: function() {
var map = this.maps[this.api];
return map.getZoom();
},
getZoomLevelForBoundingBox: function( bbox ) {
var map = this.maps[this.api];
var sw = bbox.getSouthWest().toProprietary(this.api);
var ne = bbox.getNorthEast().toProprietary(this.api);
var gLatLngBounds = new google.maps.LatLngBounds(sw, ne);
map.fitBounds(gLatLngBounds);
return map.getZoom();
},
setMapType: function(type) {
var map = this.maps[this.api];
switch(type) {
case mxn.Mapstraction.ROAD:
map.setMapTypeId(google.maps.MapTypeId.ROADMAP);
break;
case mxn.Mapstraction.SATELLITE:
map.setMapTypeId(google.maps.MapTypeId.SATELLITE);
break;
case mxn.Mapstraction.HYBRID:
map.setMapTypeId(google.maps.MapTypeId.HYBRID);
break;
case mxn.Mapstraction.PHYSICAL:
map.setMapTypeId(google.maps.MapTypeId.TERRAIN);
break;
default:
map.setMapTypeId(google.maps.MapTypeId.ROADMAP);
}
},
getMapType: function() {
var map = this.maps[this.api];
var type = map.getMapTypeId();
switch(type) {
case google.maps.MapTypeId.ROADMAP:
return mxn.Mapstraction.ROAD;
case google.maps.MapTypeId.SATELLITE:
return mxn.Mapstraction.SATELLITE;
case google.maps.MapTypeId.HYBRID:
return mxn.Mapstraction.HYBRID;
case google.maps.MapTypeId.TERRAIN:
return mxn.Mapstraction.PHYSICAL;
default:
return null;
}
},
getBounds: function () {
var map = this.maps[this.api];
var gLatLngBounds = map.getBounds();
var sw = gLatLngBounds.getSouthWest();
var ne = gLatLngBounds.getNorthEast();
return new mxn.BoundingBox(sw.lat(), sw.lng(), ne.lat(), ne.lng());
},
setBounds: function(bounds){
var map = this.maps[this.api];
var sw = bounds.getSouthWest().toProprietary(this.api);
var ne = bounds.getNorthEast().toProprietary(this.api);
var gLatLngBounds = new google.maps.LatLngBounds(sw, ne);
map.fitBounds(gLatLngBounds);
},
addImageOverlay: function(id, src, opacity, west, south, east, north, oContext) {
var map = this.maps[this.api];
// TODO: Add provider code
},
setImagePosition: function(id, oContext) {
var map = this.maps[this.api];
var topLeftPoint; var bottomRightPoint;
// TODO: Add provider code
//oContext.pixels.top = ...;
//oContext.pixels.left = ...;
//oContext.pixels.bottom = ...;
//oContext.pixels.right = ...;
},
addOverlay: function(url, autoCenterAndZoom) {
var map = this.maps[this.api];
// TODO: Add provider code
},
addTileLayer: function(tile_url, opacity, copyright_text, min_zoom, max_zoom, map_type) {
var map = this.maps[this.api];
// TODO: Add provider code
},
toggleTileLayer: function(tile_url) {
var map = this.maps[this.api];
// TODO: Add provider code
},
getPixelRatio: function() {
var map = this.maps[this.api];
// TODO: Add provider code
},
mousePosition: function(element) {
var map = this.maps[this.api];
// TODO: Add provider code
}
},
LatLonPoint: {
toProprietary: function() {
return new google.maps.LatLng(this.lat, this.lon);
},
fromProprietary: function(googlePoint) {
this.lat = googlePoint.lat();
this.lon = googlePoint.lng();
}
},
Marker: {
toProprietary: function() {
var options = {};
// do we have an Anchor?
var ax = 0; // anchor x
var ay = 0; // anchor y
if (this.iconAnchor) {
ax = this.iconAnchor[0];
ay = this.iconAnchor[1];
}
var gAnchorPoint = new google.maps.Point(ax,ay);
if (this.iconUrl) {
options.icon = new google.maps.MarkerImage(
this.iconUrl,
new google.maps.Size(this.iconSize[0], this.iconSize[1]),
new google.maps.Point(0,0),
gAnchorPoint
);
// do we have a Shadow?
if (this.iconShadowUrl) {
if (this.iconShadowSize) {
var x = this.iconShadowSize[0];
var y = this.iconShadowSize[1];
options.shadow = new google.maps.MarkerImage(
this.iconShadowUrl,
new google.maps.Size(x,y),
new google.maps.Point(0,0),
gAnchorPoint
);
}
else {
options.shadow = new google.maps.MarkerImage(this.iconShadowUrl);
}
}
}
if (this.draggable){
options.draggable = this.draggable;
}
if (this.labelText){
options.title = this.labelText;
}
if (this.imageMap){
options.shape = {
coord: this.imageMap,
type: 'poly'
};
}
options.position = this.location.toProprietary(this.api);
options.map = this.map;
var marker = new google.maps.Marker(options);
if (this.infoBubble){
var infowindow = new google.maps.InfoWindow({
content: this.infoBubble
});
var event_action = "click";
if (this.hover) {
event_action = "mouseover";
}
google.maps.event.addListener(marker, event_action, function() { infowindow.open(this.map,marker); });
}
if (this.hoverIconUrl){
var gSize = new google.maps.Size(this.iconSize[0], this.iconSize[1]);
var zerozero = new google.maps.Point(0,0);
var hIcon = new google.maps.MarkerImage(
this.hoverIconUrl,
gSize,
zerozero,
gAnchorPoint
);
var Icon = new google.maps.MarkerImage(
this.iconUrl,
gSize,
zerozero,
gAnchorPoint
);
google.maps.event.addListener(
marker,
"mouseover",
function(){
marker.setIcon(hIcon);
}
);
google.maps.event.addListener(
marker,
"mouseout",
function(){ marker.setIcon(Icon); }
);
}
google.maps.event.addListener(marker, 'click', function() {
marker.mapstraction_marker.click.fire();
});
return marker;
},
openBubble: function() {
var infowindow = new google.maps.InfoWindow({
content: this.infoBubble
});
infowindow.open(this.map,this.proprietary_marker);
},
hide: function() {
this.proprietary_marker.setOptions({visible:false});
},
show: function() {
this.proprietary_marker.setOptions({visible:true});
},
update: function() {
// TODO: Add provider code
}
},
Polyline: {
toProprietary: function() {
var pts = this.points;
var gpts = [];
for (var i=0; i<pts.length; i++) {
gpts.push(pts[i].toProprietary(this.api));
}
if (this.closed || pts[0].equals(pts[pts.length - 1])) {
return new google.maps.Polygon({
path: gpts,
strokeColor: this.color,
strokeOpacity: this.opacity,
strokeWeight: this.width,
fillColor: this.fillColor || "#5462E3",
fillOpacity: this.opacity || "0.3"
});
}
else {
return new google.maps.Polyline({
path: gpts,
strokeColor: this.color,
strokeOpacity: this.opacity,
strokeWeight: this.width
});
}
},
show: function() {
throw 'Not implemented';
},
hide: function() {
throw 'Not implemented';
}
}
});

565
src/mapstraction/mxn.js Normal file
View File

@ -0,0 +1,565 @@
/*
Copyright (c) 2010 Tom Carden, Steve Coast, Mikel Maron, Andrew Turner, Henri Bergius, Rob Moran, Derek Fowler
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* 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.
* 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.
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.
*/
// Auto-load scripts
//
// specify which map providers to load by using
// <script src="mxn.js?(provider1,provider2,[module1,module2])" ...
// in your HTML
//
// for each provider mxn.provider.module.js and mxn.module.js will be loaded
// module 'core' is always loaded
//
// NOTE: if you call without providers
// <script src="mxn.js" ...
// no scripts will be loaded at all and it is then up to you to load the scripts independently
(function() {
var providers = null;
var modules = 'core';
var scriptBase;
var scripts = document.getElementsByTagName('script');
// Determine which scripts we need to load
for (var i = 0; i < scripts.length; i++) {
var match = scripts[i].src.replace(/%20/g , '').match(/^(.*?)mxn\.js(\?\(\[?(.*?)\]?\))?$/);
if (match !== null) {
scriptBase = match[1];
if (match[3]) {
var settings = match[3].split(',[');
providers = settings[0].replace(']' , '');
if (settings[1]) {
modules += ',' + settings[1];
}
}
break;
}
}
if (providers === null || providers == 'none') {
return; // Bail out if no auto-load has been found
}
providers = providers.replace(/ /g, '').split(',');
modules = modules.replace(/ /g, '').split(',');
// Actually load the scripts
var scriptTagStart = '<script type="text/javascript" src="' + scriptBase + 'mxn.';
var scriptTagEnd = '.js"></script>';
var scriptsAry = [];
for (i = 0; i < modules.length; i++) {
scriptsAry.push(scriptTagStart + modules[i] + scriptTagEnd);
for (var j = 0; j < providers.length; j++) {
scriptsAry.push(scriptTagStart + providers[j] + '.' + modules[i] + scriptTagEnd);
}
}
document.write(scriptsAry.join(''));
})();
(function(){
// holds all our implementing functions
var apis = {};
// Our special private methods
/**
* Calls the API specific implementation of a particular method.
* Deferrable: If the API implmentation includes a deferable hash such as { getCenter: true, setCenter: true},
* then the methods calls mentioned with in it will be queued until runDeferred is called.
*
* @private
*/
var invoke = function(sApiId, sObjName, sFnName, oScope, args){
if(!hasImplementation(sApiId, sObjName, sFnName)) {
throw 'Method ' + sFnName + ' of object ' + sObjName + ' is not supported by API ' + sApiId + '. Are you missing a script tag?';
}
if(typeof(apis[sApiId][sObjName].deferrable) != 'undefined' && apis[sApiId][sObjName].deferrable[sFnName] === true) {
mxn.deferUntilLoaded.call(oScope, function() {return apis[sApiId][sObjName][sFnName].apply(oScope, args);} );
}
else {
return apis[sApiId][sObjName][sFnName].apply(oScope, args);
}
};
/**
* Determines whether the specified API provides an implementation for the
* specified object and function name.
* @private
*/
var hasImplementation = function(sApiId, sObjName, sFnName){
if(typeof(apis[sApiId]) == 'undefined') {
throw 'API ' + sApiId + ' not loaded. Are you missing a script tag?';
}
if(typeof(apis[sApiId][sObjName]) == 'undefined') {
throw 'Object definition ' + sObjName + ' in API ' + sApiId + ' not loaded. Are you missing a script tag?';
}
return typeof(apis[sApiId][sObjName][sFnName]) == 'function';
};
/**
* @name mxn
* @namespace
*/
var mxn = window.mxn = /** @lends mxn */ {
/**
* Registers a set of provider specific implementation functions.
* @function
* @param {String} sApiId The API ID to register implementing functions for.
* @param {Object} oApiImpl An object containing the API implementation.
*/
register: function(sApiId, oApiImpl){
if(!apis.hasOwnProperty(sApiId)){
apis[sApiId] = {};
}
mxn.util.merge(apis[sApiId], oApiImpl);
},
/**
* Adds a list of named proxy methods to the prototype of a
* specified constructor function.
* @function
* @param {Function} func Constructor function to add methods to
* @param {Array} aryMethods Array of method names to create
* @param {Boolean} bWithApiArg Optional. Whether the proxy methods will use an API argument
*/
addProxyMethods: function(func, aryMethods, bWithApiArg){
for(var i = 0; i < aryMethods.length; i++) {
var sMethodName = aryMethods[i];
if(bWithApiArg){
func.prototype[sMethodName] = new Function('return this.invoker.go(\'' + sMethodName + '\', arguments, { overrideApi: true } );');
}
else {
func.prototype[sMethodName] = new Function('return this.invoker.go(\'' + sMethodName + '\', arguments);');
}
}
},
checkLoad: function(funcDetails){
if(this.loaded[this.api] === false) {
var scope = this;
this.onload[this.api].push( function() { funcDetails.callee.apply(scope, funcDetails); } );
return true;
}
return false;
},
deferUntilLoaded: function(fnCall) {
if(this.loaded[this.api] === false) {
var scope = this;
this.onload[this.api].push( fnCall );
} else {
fnCall.call(this);
}
},
/**
* Bulk add some named events to an object.
* @function
* @param {Object} oEvtSrc The event source object.
* @param {String[]} aEvtNames Event names to add.
*/
addEvents: function(oEvtSrc, aEvtNames){
for(var i = 0; i < aEvtNames.length; i++){
var sEvtName = aEvtNames[i];
if(sEvtName in oEvtSrc){
throw 'Event or method ' + sEvtName + ' already declared.';
}
oEvtSrc[sEvtName] = new mxn.Event(sEvtName, oEvtSrc);
}
}
};
/**
* Instantiates a new Event
* @constructor
* @param {String} sEvtName The name of the event.
* @param {Object} oEvtSource The source object of the event.
*/
mxn.Event = function(sEvtName, oEvtSource){
var handlers = [];
if(!sEvtName){
throw 'Event name must be provided';
}
/**
* Add a handler to the Event.
* @param {Function} fn The handler function.
* @param {Object} ctx The context of the handler function.
*/
this.addHandler = function(fn, ctx){
handlers.push({context: ctx, handler: fn});
};
/**
* Remove a handler from the Event.
* @param {Function} fn The handler function.
* @param {Object} ctx The context of the handler function.
*/
this.removeHandler = function(fn, ctx){
for(var i = 0; i < handlers.length; i++){
if(handlers[i].handler == fn && handlers[i].context == ctx){
handlers.splice(i, 1);
}
}
};
/**
* Remove all handlers from the Event.
*/
this.removeAllHandlers = function(){
handlers = [];
};
/**
* Fires the Event.
* @param {Object} oEvtArgs Event arguments object to be passed to the handlers.
*/
this.fire = function(oEvtArgs){
var args = [sEvtName, oEvtSource, oEvtArgs];
for(var i = 0; i < handlers.length; i++){
handlers[i].handler.apply(handlers[i].context, args);
}
};
};
/**
* Creates a new Invoker, a class which helps with on-the-fly
* invocation of the correct API methods.
* @constructor
* @param {Object} aobj The core object whose methods will make cals to go()
* @param {String} asClassName The name of the Mapstraction class to be invoked, normally the same name as aobj's constructor function
* @param {Function} afnApiIdGetter The function on object aobj which will return the active API ID
*/
mxn.Invoker = function(aobj, asClassName, afnApiIdGetter){
var obj = aobj;
var sClassName = asClassName;
var fnApiIdGetter = afnApiIdGetter;
var defOpts = {
overrideApi: false, // {Boolean} API ID is overridden by value in first argument
context: null, // {Object} Local vars can be passed from the body of the method to the API method within this object
fallback: null // {Function} If an API implementation doesn't exist this function is run instead
};
/**
* Invoke the API implementation of a specific method.
* @param {String} sMethodName The method name to invoke
* @param {Array} args Arguments to pass on
* @param {Object} oOptions Optional. Extra options for invocation
* @param {Boolean} oOptions.overrideApi When true the first argument is used as the API ID.
* @param {Object} oOptions.context A context object for passing extra information on to the provider implementation.
* @param {Function} oOptions.fallback A fallback function to run if the provider implementation is missing.
*/
this.go = function(sMethodName, args, oOptions){
// make sure args is an array
args = Array.prototype.slice.apply(args);
if(typeof(oOptions) == 'undefined'){
oOptions = defOpts;
}
var sApiId;
if(oOptions.overrideApi){
sApiId = args.shift();
}
else {
sApiId = fnApiIdGetter.apply(obj);
}
if(typeof(sApiId) != 'string'){
throw 'API ID not available.';
}
if(typeof(oOptions.context) != 'undefined' && oOptions.context !== null){
args.push(oOptions.context);
}
if(typeof(oOptions.fallback) == 'function' && !hasImplementation(sApiId, sClassName, sMethodName)){
// we've got no implementation but have got a fallback function
return oOptions.fallback.apply(obj, args);
}
else {
return invoke(sApiId, sClassName, sMethodName, obj, args);
}
};
};
/**
* @namespace
*/
mxn.util = {
/**
* Merges properties of one object into another recursively.
* @param {Object} oRecv The object receiveing properties
* @param {Object} oGive The object donating properties
*/
merge: function(oRecv, oGive){
for (var sPropName in oGive){
if (oGive.hasOwnProperty(sPropName)) {
if(!oRecv.hasOwnProperty(sPropName)){
oRecv[sPropName] = oGive[sPropName];
}
else {
mxn.util.merge(oRecv[sPropName], oGive[sPropName]);
}
}
}
},
/**
* $m, the dollar function, elegantising getElementById()
* @return An HTML element or array of HTML elements
*/
$m: function() {
var elements = [];
for (var i = 0; i < arguments.length; i++) {
var element = arguments[i];
if (typeof(element) == 'string') {
element = document.getElementById(element);
}
if (arguments.length == 1) {
return element;
}
elements.push(element);
}
return elements;
},
/**
* loadScript is a JSON data fetcher
* @param {String} src URL to JSON file
* @param {Function} callback Callback function
*/
loadScript: function(src, callback) {
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = src;
if (callback) {
if(script.addEventListener){
script.addEventListener('load', callback, true);
}
else if(script.attachEvent){
var done = false;
script.attachEvent("onreadystatechange",function(){
if ( !done && document.readyState === "complete" ) {
done = true;
callback();
}
});
}
}
var h = document.getElementsByTagName('head')[0];
h.appendChild( script );
return;
},
/**
*
* @param {Object} point
* @param {Object} level
*/
convertLatLonXY_Yahoo: function(point, level) { //Mercator
var size = 1 << (26 - level);
var pixel_per_degree = size / 360.0;
var pixel_per_radian = size / (2 * Math.PI);
var origin = new YCoordPoint(size / 2 , size / 2);
var answer = new YCoordPoint();
answer.x = Math.floor(origin.x + point.lon * pixel_per_degree);
var sin = Math.sin(point.lat * Math.PI / 180.0);
answer.y = Math.floor(origin.y + 0.5 * Math.log((1 + sin) / (1 - sin)) * -pixel_per_radian);
return answer;
},
/**
* Load a stylesheet from a remote file.
* @param {String} href URL to the CSS file
*/
loadStyle: function(href) {
var link = document.createElement('link');
link.type = 'text/css';
link.rel = 'stylesheet';
link.href = href;
document.getElementsByTagName('head')[0].appendChild(link);
return;
},
/**
* getStyle provides cross-browser access to css
* @param {Object} el HTML Element
* @param {String} prop Style property name
*/
getStyle: function(el, prop) {
var y;
if (el.currentStyle) {
y = el.currentStyle[prop];
}
else if (window.getComputedStyle) {
y = window.getComputedStyle( el, '').getPropertyValue(prop);
}
return y;
},
/**
* Convert longitude to metres
* http://www.uwgb.edu/dutchs/UsefulData/UTMFormulas.HTM
* "A degree of longitude at the equator is 111.2km... For other latitudes,
* multiply by cos(lat)"
* assumes the earth is a sphere but good enough for our purposes
* @param {Float} lon
* @param {Float} lat
*/
lonToMetres: function(lon, lat) {
return lon * (111200 * Math.cos(lat * (Math.PI / 180)));
},
/**
* Convert metres to longitude
* @param {Object} m
* @param {Object} lat
*/
metresToLon: function(m, lat) {
return m / (111200 * Math.cos(lat * (Math.PI / 180)));
},
/**
* Convert kilometres to miles
* @param {Float} km
* @returns {Float} miles
*/
KMToMiles: function(km) {
return km / 1.609344;
},
/**
* Convert miles to kilometres
* @param {Float} miles
* @returns {Float} km
*/
milesToKM: function(miles) {
return miles * 1.609344;
},
// stuff to convert google zoom levels to/from degrees
// assumes zoom 0 = 256 pixels = 360 degrees
// zoom 1 = 256 pixels = 180 degrees
// etc.
/**
*
* @param {Object} pixels
* @param {Object} zoom
*/
getDegreesFromGoogleZoomLevel: function(pixels, zoom) {
return (360 * pixels) / (Math.pow(2, zoom + 8));
},
/**
*
* @param {Object} pixels
* @param {Object} degrees
*/
getGoogleZoomLevelFromDegrees: function(pixels, degrees) {
return mxn.util.logN((360 * pixels) / degrees, 2) - 8;
},
/**
*
* @param {Object} number
* @param {Object} base
*/
logN: function(number, base) {
return Math.log(number) / Math.log(base);
},
/**
* Returns array of loaded provider apis
* @returns {Array} providers
*/
getAvailableProviders : function () {
var providers = [];
for (var propertyName in apis){
if (apis.hasOwnProperty(propertyName)) {
providers.push(propertyName);
}
}
return providers;
},
/**
* Formats a string, inserting values of subsequent parameters at specified
* locations. e.g. stringFormat('{0} {1}', 'hello', 'world');
*/
stringFormat: function(strIn){
var replaceRegEx = /\{\d+\}/g;
var args = Array.slice.apply(arguments);
args.shift();
return strIn.replace(replaceRegEx, function(strVal){
var num = strVal.slice(1, -1);
return args[num];
});
}
};
/**
* Class for converting between HTML and RGB integer color formats.
* Accepts either a HTML color string argument or three integers for R, G and B.
* @constructor
*/
mxn.util.Color = function() {
if(arguments.length == 3) {
this.red = arguments[0];
this.green = arguments[1];
this.blue = arguments[2];
}
else if(arguments.length == 1) {
this.setHexColor(arguments[0]);
}
};
mxn.util.Color.prototype.reHex = /^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/;
/**
* Set the color from the supplied HTML hex string.
* @param {String} strHexColor A HTML hex color string e.g. '#00FF88'.
*/
mxn.util.Color.prototype.setHexColor = function(strHexColor) {
var match = strHexColor.match(this.reHex);
if(match) {
// grab the code - strips off the preceding # if there is one
strHexColor = match[1];
}
else {
throw 'Invalid HEX color format, expected #000, 000, #000000 or 000000';
}
// if a three character hex code was provided, double up the values
if(strHexColor.length == 3) {
strHexColor = strHexColor.replace(/\w/g, function(str){return str.concat(str);});
}
this.red = parseInt(strHexColor.substr(0,2), 16);
this.green = parseInt(strHexColor.substr(2,2), 16);
this.blue = parseInt(strHexColor.substr(4,2), 16);
};
/**
* Retrieve the color value as an HTML hex string.
* @returns {String} Format '#00FF88'.
*/
mxn.util.Color.prototype.getHexColor = function() {
var rgb = this.blue | (this.green << 8) | (this.red << 16);
var hexString = rgb.toString(16).toUpperCase();
if(hexString.length < 6){
hexString = '0' + hexString;
}
return '#' + hexString;
};
})();

View File

@ -0,0 +1,523 @@
/*
Copyright (c) 2010 Tom Carden, Steve Coast, Mikel Maron, Andrew Turner, Henri Bergius, Rob Moran, Derek Fowler
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* 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.
* 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.
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.
*/
mxn.register('openlayers', {
Mapstraction: {
init: function(element, api){
var me = this;
this.maps[api] = new OpenLayers.Map(
element.id,
{
maxExtent: new OpenLayers.Bounds(-20037508.34,-20037508.34,20037508.34,20037508.34),
maxResolution:156543,
numZoomLevels:18,
units:'meters',
projection: "EPSG:41001"
}
);
this.layers.osmmapnik = new OpenLayers.Layer.TMS(
'OSM Mapnik',
[
"http://a.tile.openstreetmap.org/",
"http://b.tile.openstreetmap.org/",
"http://c.tile.openstreetmap.org/"
],
{
type:'png',
getURL: function (bounds) {
var res = this.map.getResolution();
var x = Math.round ((bounds.left - this.maxExtent.left) / (res * this.tileSize.w));
var y = Math.round ((this.maxExtent.top - bounds.top) / (res * this.tileSize.h));
var z = this.map.getZoom();
var limit = Math.pow(2, z);
if (y < 0 || y >= limit) {
return null;
} else {
x = ((x % limit) + limit) % limit;
var path = z + "/" + x + "/" + y + "." + this.type;
var url = this.url;
if (url instanceof Array) {
url = this.selectUrl(path, url);
}
return url + path;
}
},
displayOutsideMaxExtent: true
}
);
this.layers.osm = new OpenLayers.Layer.TMS(
'OSM',
[
"http://a.tah.openstreetmap.org/Tiles/tile.php/",
"http://b.tah.openstreetmap.org/Tiles/tile.php/",
"http://c.tah.openstreetmap.org/Tiles/tile.php/"
],
{
type:'png',
getURL: function (bounds) {
var res = this.map.getResolution();
var x = Math.round ((bounds.left - this.maxExtent.left) / (res * this.tileSize.w));
var y = Math.round ((this.maxExtent.top - bounds.top) / (res * this.tileSize.h));
var z = this.map.getZoom();
var limit = Math.pow(2, z);
if (y < 0 || y >= limit) {
return null;
} else {
x = ((x % limit) + limit) % limit;
var path = z + "/" + x + "/" + y + "." + this.type;
var url = this.url;
if (url instanceof Array) {
url = this.selectUrl(path, url);
}
return url + path;
}
},
displayOutsideMaxExtent: true
}
);
this.maps[api].addLayer(this.layers.osmmapnik);
this.maps[api].addLayer(this.layers.osm);
this.loaded[api] = true;
},
applyOptions: function(){
// var map = this.maps[this.api];
// var myOptions = [];
// if (this.options.enableDragging) {
// myOptions.draggable = true;
// }
// if (this.options.enableScrollWheelZoom){
// myOptions.scrollwheel = true;
// }
// map.setOptions(myOptions);
},
resizeTo: function(width, height){
this.currentElement.style.width = width;
this.currentElement.style.height = height;
this.maps[this.api].updateSize();
},
addControls: function( args ) {
var map = this.maps[this.api];
// FIXME: OpenLayers has a bug removing all the controls says crschmidt
for (var i = map.controls.length; i>1; i--) {
map.controls[i-1].deactivate();
map.removeControl(map.controls[i-1]);
}
if ( args.zoom == 'large' ) {
map.addControl(new OpenLayers.Control.PanZoomBar());
}
else if ( args.zoom == 'small' ) {
map.addControl(new OpenLayers.Control.ZoomPanel());
if ( args.pan) {
map.addControl(new OpenLayers.Control.PanPanel());
}
}
else {
if ( args.pan){
map.addControl(new OpenLayers.Control.PanPanel());
}
}
if ( args.overview ) {
map.addControl(new OpenLayers.Control.OverviewMap());
}
if ( args.map_type ) {
map.addControl(new OpenLayers.Control.LayerSwitcher());
}
},
addSmallControls: function() {
var map = this.maps[this.api];
this.addControlsArgs.pan = false;
this.addControlsArgs.scale = false;
this.addControlsArgs.zoom = 'small';
map.addControl(new OpenLayers.Control.ZoomBox());
map.addControl(new OpenLayers.Control.LayerSwitcher({
'ascending':false
}));
},
addLargeControls: function() {
var map = this.maps[this.api];
map.addControl(new OpenLayers.Control.PanZoomBar());
this.addControlsArgs.pan = true;
this.addControlsArgs.zoom = 'large';
},
addMapTypeControls: function() {
var map = this.maps[this.api];
map.addControl( new OpenLayers.Control.LayerSwitcher({
'ascending':false
}) );
this.addControlsArgs.map_type = true;
},
setCenterAndZoom: function(point, zoom) {
var map = this.maps[this.api];
var pt = point.toProprietary(this.api);
map.setCenter(point.toProprietary(this.api), zoom);
},
addMarker: function(marker, old) {
var map = this.maps[this.api];
var pin = marker.toProprietary(this.api);
if (!this.layers.markers) {
this.layers.markers = new OpenLayers.Layer.Markers('markers');
map.addLayer(this.layers.markers);
}
this.layers.markers.addMarker(pin);
return pin;
},
removeMarker: function(marker) {
var map = this.maps[this.api];
var pin = marker.toProprietary(this.api);
this.layers.markers.removeMarker(pin);
pin.destroy();
},
declutterMarkers: function(opts) {
throw 'Not supported';
},
addPolyline: function(polyline, old) {
var map = this.maps[this.api];
var pl = polyline.toProprietary(this.api);
if (!this.layers.polylines) {
this.layers.polylines = new OpenLayers.Layer.Vector('polylines');
map.addLayer(this.layers.polylines);
}
polyline.setChild(pl);
this.layers.polylines.addFeatures([pl]);
return pl;
},
removePolyline: function(polyline) {
var map = this.maps[this.api];
var pl = polyline.toProprietary(this.api);
this.layers.polylines.removeFeatures([pl]);
},
removeAllPolylines: function() {
var olpolylines = [];
for(var i = 0, length = this.polylines.length; i < length; i++){
olpolylines.push(this.polylines[i].toProprietary(this.api));
}
if (this.layers.polylines) {
this.layers.polylines.removeFeatures(olpolylines);
}
},
getCenter: function() {
var map = this.maps[this.api];
var pt = map.getCenter();
var mxnPt = new mxn.LatLonPoint();
mxnPt.fromProprietary(this.api, pt);
return mxnPt;
},
setCenter: function(point, options) {
var map = this.maps[this.api];
var pt = point.toProprietary(this.api);
map.setCenter(pt);
},
setZoom: function(zoom) {
var map = this.maps[this.api];
map.zoomTo(zoom);
},
getZoom: function() {
var map = this.maps[this.api];
return map.zoom;
},
getZoomLevelForBoundingBox: function( bbox ) {
var map = this.maps[this.api];
// throw 'Not implemented';
return zoom;
},
setMapType: function(type) {
var map = this.maps[this.api];
throw 'Not implemented (setMapType)';
// switch(type) {
// case mxn.Mapstraction.ROAD:
// map.setMapTypeId(google.maps.MapTypeId.ROADMAP);
// break;
// case mxn.Mapstraction.SATELLITE:
// map.setMapTypeId(google.maps.MapTypeId.SATELLITE);
// break;
// case mxn.Mapstraction.HYBRID:
// map.setMapTypeId(google.maps.MapTypeId.HYBRID);
// break;
// default:
// map.setMapTypeId(google.maps.MapTypeId.ROADMAP);
// }
},
getMapType: function() {
var map = this.maps[this.api];
// TODO: implement actual layer support
return mxn.Mapstraction.ROAD;
// var type = map.getMapTypeId();
// switch(type) {
// case google.maps.MapTypeId.ROADMAP:
// return mxn.Mapstraction.ROAD;
// case google.maps.MapTypeId.SATELLITE:
// return mxn.Mapstraction.SATELLITE;
// case google.maps.MapTypeId.HYBRID:
// return mxn.Mapstraction.HYBRID;
// //case google.maps.MapTypeId.TERRAIN:
// // return something;
// default:
// return null;
// }
},
getBounds: function () {
var map = this.maps[this.api];
var olbox = map.calculateBounds();
return new mxn.BoundingBox(olbox.bottom, olbox.left, olbox.top, olbox.right);
},
setBounds: function(bounds){
var map = this.maps[this.api];
var sw = bounds.getSouthWest();
var ne = bounds.getNorthEast();
if(sw.lon > ne.lon) {
sw.lon -= 360;
}
var obounds = new OpenLayers.Bounds();
obounds.extend(new mxn.LatLonPoint(sw.lat,sw.lon).toProprietary(this.api));
obounds.extend(new mxn.LatLonPoint(ne.lat,ne.lon).toProprietary(this.api));
map.zoomToExtent(obounds);
},
addImageOverlay: function(id, src, opacity, west, south, east, north, oContext) {
var map = this.maps[this.api];
// TODO: Add provider code
},
setImagePosition: function(id, oContext) {
var map = this.maps[this.api];
var topLeftPoint; var bottomRightPoint;
// TODO: Add provider code
//oContext.pixels.top = ...;
//oContext.pixels.left = ...;
//oContext.pixels.bottom = ...;
//oContext.pixels.right = ...;
},
addOverlay: function(url, autoCenterAndZoom) {
var map = this.maps[this.api];
// TODO: Add provider code
},
addTileLayer: function(tile_url, opacity, copyright_text, min_zoom, max_zoom) {
var map = this.maps[this.api];
// TODO: Add provider code
},
toggleTileLayer: function(tile_url) {
var map = this.maps[this.api];
// TODO: Add provider code
},
getPixelRatio: function() {
var map = this.maps[this.api];
// TODO: Add provider code
},
mousePosition: function(element) {
var map = this.maps[this.api];
// TODO: Add provider code
}
},
LatLonPoint: {
toProprietary: function() {
var ollon = this.lon * 20037508.34 / 180;
var ollat = Math.log(Math.tan((90 + this.lat) * Math.PI / 360)) / (Math.PI / 180);
ollat = ollat * 20037508.34 / 180;
return new OpenLayers.LonLat(ollon, ollat);
},
fromProprietary: function(olPoint) {
var lon = (olPoint.lon / 20037508.34) * 180;
var lat = (olPoint.lat / 20037508.34) * 180;
lat = 180/Math.PI * (2 * Math.atan(Math.exp(lat * Math.PI / 180)) - Math.PI / 2);
this.lon = lon;
this.lat = lat;
}
},
Marker: {
toProprietary: function() {
var size, anchor, icon;
if(this.iconSize) {
size = new OpenLayers.Size(this.iconSize[0], this.iconSize[1]);
}
else {
size = new OpenLayers.Size(21,25);
}
if(this.iconAnchor) {
anchor = new OpenLayers.Pixel(this.iconAnchor[0], this.iconAnchor[1]);
}
else {
// FIXME: hard-coding the anchor point
anchor = new OpenLayers.Pixel(-(size.w/2), -size.h);
}
if(this.iconUrl) {
icon = new OpenLayers.Icon(this.iconUrl, size, anchor);
}
else {
icon = new OpenLayers.Icon('http://openlayers.org/dev/img/marker-gold.png', size, anchor);
}
var marker = new OpenLayers.Marker(this.location.toProprietary("openlayers"), icon);
if(this.infoBubble) {
var popup = new OpenLayers.Popup(null,
this.location.toProprietary("openlayers"),
new OpenLayers.Size(100,100),
this.infoBubble,
true
);
popup.autoSize = true;
var theMap = this.map;
if(this.hover) {
marker.events.register("mouseover", marker, function(event) {
theMap.addPopup(popup);
popup.show();
});
marker.events.register("mouseout", marker, function(event) {
popup.hide();
theMap.removePopup(popup);
});
}
else {
var shown = false;
marker.events.register("mousedown", marker, function(event) {
if (shown) {
popup.hide();
theMap.removePopup(popup);
shown = false;
} else {
theMap.addPopup(popup);
popup.show();
shown = true;
}
});
}
}
if(this.hoverIconUrl) {
// TODO
}
if(this.infoDiv){
// TODO
}
return marker;
},
openBubble: function() {
// TODO: Add provider code
},
hide: function() {
this.proprietary_marker.setOptions({visible:false});
},
show: function() {
this.proprietary_marker.setOptions({visible:true});
},
update: function() {
// TODO: Add provider code
}
},
Polyline: {
toProprietary: function() {
var olpolyline;
var olpoints = [];
var ring;
var style = {
strokeColor: this.color || "#000000",
strokeOpacity: this.opacity || 1,
strokeWidth: this.width || 1,
fillColor: this.fillColor || "#000000",
fillOpacity: this.getAttribute('fillOpacity') || 0.2
};
//TODO Handle closed attribute
for (var i = 0, length = this.points.length ; i< length; i++){
olpoint = this.points[i].toProprietary("openlayers");
olpoints.push(new OpenLayers.Geometry.Point(olpoint.lon, olpoint.lat));
}
if (this.closed) {
// a closed polygon
ring = new OpenLayers.Geometry.LinearRing(olpoints);
} else {
// a line
ring = new OpenLayers.Geometry.LineString(olpoints);
}
olpolyline = new OpenLayers.Feature.Vector(ring, null, style);
return olpolyline;
},
show: function() {
throw 'Not implemented';
},
hide: function() {
throw 'Not implemented';
}
}
});