Permalink
Browse files

Fixing GeoCommons support to updated API

  • Loading branch information...
1 parent 0510d3f commit c40933fa41b05658cd8893e0836f01dce6ae922c Andrew Turner committed Feb 26, 2012
View
66 build/2.0.11/mxn.geocommons.core.js
@@ -1,21 +1,9 @@
-/*
-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', {
+mxn.register('geocommons', {
Mapstraction: {
// These methods can be called anytime but will only execute
- // once the map has loaded.
+ // once the map has loaded.
deferrable: {
applyOptions: true,
resizeTo: true,
@@ -40,36 +28,34 @@ mxn.register('geocommons', {
mousePosition: true
},
- init: function(element, api) {
+ 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({
+ this.maps[api] = 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;
+ map_id: 127297,
+ flashvars: {},
+ onMapLoaded: 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){
+ resizeTo: function(width, height){
var map = this.maps[this.api];
map.setSize(width,height);
},
@@ -78,10 +64,10 @@ mxn.register('geocommons', {
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("Styles", args.styles || false);
map.showControl("Basemap", args.map_type || false);
- map.showControl("Legend", args.legend || false, "open");
- // showControl("Legend", true, "close");
+ map.showControl("Legend", args.legend || false, "open");
+ // showControl("Legend", true, "close");
},
addSmallControls: function() {
@@ -91,7 +77,7 @@ mxn.register('geocommons', {
legend: "open"
});
// showControl("Zoom", args.zoom);
- // showControl("Legend", args.legend, "open");
+ // showControl("Legend", args.legend, "open");
},
addLargeControls: function() {
@@ -115,7 +101,7 @@ mxn.register('geocommons', {
// TODO: Add provider code
},
- setCenterAndZoom: function(point, zoom) {
+ setCenterAndZoom: function(point, zoom) {
var map = this.maps[this.api];
map.setCenterZoom(point.lat, point.lon,zoom);
},
@@ -128,7 +114,7 @@ mxn.register('geocommons', {
setCenter: function(point, options) {
var map = this.maps[this.api];
- map.setCenter(point.lat, point.lon);
+ map.setCenter(point.lat, point.lon);
},
setZoom: function(zoom) {
@@ -167,14 +153,14 @@ mxn.register('geocommons', {
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()) {
+ switch(map.getBasemap().name) {
case "OpenStreetMap (road)":
return mxn.Mapstraction.ROAD;
case "BlueMarble":
@@ -183,13 +169,13 @@ mxn.register('geocommons', {
return mxn.Mapstraction.HYBRID;
default:
return null;
- }
-
+ }
},
getBounds: function () {
var map = this.maps[this.api];
var extent = map.getExtent();
+ console.log([extent.northWest.lat, extent.southEast.lon, extent.southEast.lat, extent.northWest.lon]);
return new mxn.BoundingBox( extent.northWest.lat, extent.southEast.lon, extent.southEast.lat, extent.northWest.lon);
},
@@ -240,13 +226,13 @@ mxn.register('geocommons', {
getPixelRatio: function() {
var map = this.maps[this.api];
- // TODO: Add provider code
+ // TODO: Add provider code
},
mousePosition: function(element) {
var map = this.maps[this.api];
- // TODO: Add provider code
+ // TODO: Add provider code
},
addMarker: function(marker, old) {
var map = this.maps[this.api];
@@ -271,7 +257,7 @@ mxn.register('geocommons', {
addPolyline: function(polyline, old) {
var map = this.maps[this.api];
var pl = polyline.toProprietary(this.api);
- // TODO: Add provider code
+ // TODO: Add provider code
// map.addOverlay(pl);
return pl;
},
@@ -303,7 +289,7 @@ mxn.register('geocommons', {
return {};
},
- openBubble: function() {
+ openBubble: function() {
// TODO: Add provider code
},
View
222 build/2.0.12/mxn.core.js
@@ -1,15 +1,3 @@
-/*
-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.
-*/
(function(){
/**
@@ -61,14 +49,18 @@ var Mapstraction = mxn.Mapstraction = function(element, api, debug) {
this.eventListeners = [];
/**
+ * The array of all layers that have been added to the map.
+ */
+ this.tileLayers = [];
+
+ /**
* The markers currently loaded.
* @name mxn.Mapstraction#markers
* @property
* @type {Array}
*/
this.markers = [];
- this.layers = [];
-
+
/**
* The polylines currently loaded.
* @name mxn.Mapstraction#polylines
@@ -139,7 +131,7 @@ var Mapstraction = mxn.Mapstraction = function(element, api, debug) {
'changeZoom',
/**
- * Marker is removed {marker: Marker}
+ * Marker is added {marker: Marker}
* @name mxn.Mapstraction#markerAdded
* @event
*/
@@ -239,6 +231,7 @@ mxn.addProxyMethods(Mapstraction, [
* mxn.Mapstraction.ROAD
* mxn.Mapstraction.SATELLITE
* mxn.Mapstraction.HYBRID
+ * mxn.Mapstraction.PHYSICAL
* @name mxn.Mapstraction#getMapType
* @function
* @returns {Number}
@@ -323,6 +316,7 @@ mxn.addProxyMethods(Mapstraction, [
* mxn.Mapstraction.ROAD
* mxn.Mapstraction.SATELLITE
* mxn.Mapstraction.HYBRID
+ * mxn.Mapstraction.PHYSICAL
* @name mxn.Mapstraction#setMapType
* @function
* @param {Number} type
@@ -746,43 +740,40 @@ Mapstraction.prototype.removeAllPolylines = function() {
}
};
-/**
- * autoCenterAndZoom sets the center and zoom of the map to the smallest bounding box
- * containing all markers
- */
-Mapstraction.prototype.autoCenterAndZoom = function() {
- var lat_max = -90;
- var lat_min = 90;
- var lon_max = -180;
- var lon_min = 180;
- var lat, lon;
- var checkMinMax = function(){
- if (lat > lat_max) {
- lat_max = lat;
- }
- if (lat < lat_min) {
- lat_min = lat;
- }
- if (lon > lon_max) {
- lon_max = lon;
- }
- if (lon < lon_min) {
- lon_min = lon;
+var collectPoints = function(bMarkers, bPolylines, predicate) {
+ var points = [];
+
+ if (bMarkers) {
+ for (var i = 0; i < this.markers.length; i++) {
+ var mark = this.markers[i];
+ if (!predicate || predicate(mark)) {
+ points.push(mark.location);
+ }
}
- };
- for (var i = 0; i < this.markers.length; i++) {
- lat = this.markers[i].location.lat;
- lon = this.markers[i].location.lon;
- checkMinMax();
}
- for(i = 0; i < this.polylines.length; i++) {
- for (var j = 0; j < this.polylines[i].points.length; j++) {
- lat = this.polylines[i].points[j].lat;
- lon = this.polylines[i].points[j].lon;
- checkMinMax();
+
+ if (bPolylines) {
+ for(i = 0; i < this.polylines.length; i++) {
+ var poly = this.polylines[i];
+ if (!predicate || predicate(poly)) {
+ for (var j = 0; j < poly.points.length; j++) {
+ points.push(poly.points[j]);
+ }
+ }
}
}
- this.setBounds( new BoundingBox(lat_min, lon_min, lat_max, lon_max) );
+
+ return points;
+};
+
+/**
+ * Sets the center and zoom of the map to the smallest bounding box
+ * containing all markers and polylines
+ */
+Mapstraction.prototype.autoCenterAndZoom = function() {
+ var points = collectPoints.call(this, true, true);
+
+ this.centerAndZoomOnPoints(points);
};
/**
@@ -791,12 +782,13 @@ Mapstraction.prototype.autoCenterAndZoom = function() {
* This is useful if you don't want to have to add markers to the map
*/
Mapstraction.prototype.centerAndZoomOnPoints = function(points) {
- var bounds = new BoundingBox(points[0].lat,points[0].lon,points[0].lat,points[0].lon);
+ var bounds = new BoundingBox(90, 180, -90, -180);
- for (var i=1, len = points.length ; i<len; i++) {
+ for (var i = 0, len = points.length; i < len; i++) {
bounds.extend(points[i]);
}
+ console.log(bounds)
this.setBounds(bounds);
};
@@ -806,88 +798,43 @@ Mapstraction.prototype.centerAndZoomOnPoints = function(points) {
* will only include markers and polylines with an attribute of "visible"
*/
Mapstraction.prototype.visibleCenterAndZoom = function() {
- var lat_max = -90;
- var lat_min = 90;
- var lon_max = -180;
- var lon_min = 180;
- var lat, lon;
- var checkMinMax = function(){
- if (lat > lat_max) {
- lat_max = lat;
- }
- if (lat < lat_min) {
- lat_min = lat;
- }
- if (lon > lon_max) {
- lon_max = lon;
- }
- if (lon < lon_min) {
- lon_min = lon;
- }
+ var predicate = function(obj) {
+ return obj.getAttribute("visible");
};
- for (var i=0; i<this.markers.length; i++) {
- if (this.markers[i].getAttribute("visible")) {
- lat = this.markers[i].location.lat;
- lon = this.markers[i].location.lon;
- checkMinMax();
- }
- }
-
- for (i=0; i<this.polylines.length; i++){
- if (this.polylines[i].getAttribute("visible")) {
- for (j=0; j<this.polylines[i].points.length; j++) {
- lat = this.polylines[i].points[j].lat;
- lon = this.polylines[i].points[j].lon;
- checkMinMax();
- }
- }
- }
-
- this.setBounds(new BoundingBox(lat_min, lon_min, lat_max, lon_max));
+ var points = collectPoints.call(this, true, true, predicate);
+
+ this.centerAndZoomOnPoints(points);
};
/**
* Automatically sets center and zoom level to show all polylines
- * Takes into account radious of polyline
- * @param {Int} radius
+ * @param {Number} padding Optional number of kilometers to pad around polyline
*/
-Mapstraction.prototype.polylineCenterAndZoom = function(radius) {
- var lat_max = -90;
- var lat_min = 90;
- var lon_max = -180;
- var lon_min = 180;
-
- for (var i=0; i < mapstraction.polylines.length; i++)
- {
- for (var j=0; j<mapstraction.polylines[i].points.length; j++)
- {
- lat = mapstraction.polylines[i].points[j].lat;
- lon = mapstraction.polylines[i].points[j].lon;
-
- latConv = lonConv = radius;
-
- if (radius > 0)
- {
- latConv = (radius / mapstraction.polylines[i].points[j].latConv());
- lonConv = (radius / mapstraction.polylines[i].points[j].lonConv());
- }
-
- if ((lat + latConv) > lat_max) {
- lat_max = (lat + latConv);
- }
- if ((lat - latConv) < lat_min) {
- lat_min = (lat - latConv);
- }
- if ((lon + lonConv) > lon_max) {
- lon_max = (lon + lonConv);
- }
- if ((lon - lonConv) < lon_min) {
- lon_min = (lon - lonConv);
- }
+Mapstraction.prototype.polylineCenterAndZoom = function(padding) {
+ padding = padding || 0;
+
+ var points = collectPoints.call(this, false, true);
+
+ if (padding > 0) {
+ var padPoints = [];
+ for (var i = 0; i < points.length; i++) {
+ var point = points[i];
+
+ var kmInOneDegreeLat = point.latConv();
+ var kmInOneDegreeLon = point.lonConv();
+
+ var latPad = padding / kmInOneDegreeLat;
+ var lonPad = padding / kmInOneDegreeLon;
+
+ var ne = new LatLonPoint(point.lat + latPad, point.lon + lonPad);
+ var sw = new LatLonPoint(point.lat - latPad, point.lon - lonPad);
+
+ padPoints.push(ne, sw);
}
+ points = points.concat(padPoints);
}
-
- this.setBounds(new BoundingBox(lat_min, lon_min, lat_max, lon_max));
+
+ this.centerAndZoomOnPoints(points);
};
/**
@@ -1045,7 +992,6 @@ Mapstraction.prototype.addTileLayer = function(tile_url, opacity, copyright_text
return;
}
- this.tileLayers = this.tileLayers || [];
opacity = opacity || 0.6;
copyright_text = copyright_text || "Mapstraction";
min_zoom = min_zoom || 1;
@@ -1255,13 +1201,10 @@ Mapstraction.prototype.getMap = function() {
* @param {double} lon is the longitude
* @exports LatLonPoint as mxn.LatLonPoint
*/
-var LatLonPoint = mxn.LatLonPoint = function(lat, lon) {
- // TODO error if undefined?
- // if (lat == undefined) alert('undefined lat');
- // if (lon == undefined) alert('undefined lon');
- this.lat = lat;
- this.lon = lon;
- this.lng = lon; // lets be lon/lng agnostic
+var LatLonPoint = mxn.LatLonPoint = function(lat, lon) {
+ this.lat = Number(lat); // force to be numeric
+ this.lon = Number(lon);
+ this.lng = this.lon; // lets be lon/lng agnostic
this.invoker = new mxn.Invoker(this, 'LatLonPoint');
};
@@ -1357,7 +1300,6 @@ LatLonPoint.prototype.lonConv = function() {
*/
var BoundingBox = mxn.BoundingBox = function(swlat, swlon, nelat, nelon) {
//FIXME throw error if box bigger than world
- //alert('new bbox ' + swlat + ',' + swlon + ',' + nelat + ',' + nelon);
this.sw = new LatLonPoint(swlat, swlon);
this.ne = new LatLonPoint(nelat, nelon);
};
@@ -1408,20 +1350,22 @@ BoundingBox.prototype.toSpan = function() {
return new LatLonPoint( Math.abs(this.sw.lat - this.ne.lat), Math.abs(this.sw.lon - this.ne.lon) );
};
+
+
/**
* extend extends the bounding box to include the new point
*/
BoundingBox.prototype.extend = function(point) {
- if(this.sw.lat > point.lat) {
+ if (this.sw.lat > point.lat) {
this.sw.lat = point.lat;
}
- if(this.sw.lon > point.lon) {
+ if (this.sw.lon > point.lon) {
this.sw.lon = point.lon;
}
- if(this.ne.lat < point.lat) {
+ if (this.ne.lat < point.lat) {
this.ne.lat = point.lat;
}
- if(this.ne.lon < point.lon) {
+ if (this.ne.lon < point.lon) {
this.ne.lon = point.lon;
}
return;
@@ -1619,7 +1563,7 @@ Marker.prototype.setIcon = function(iconUrl, iconSize, iconAnchor) {
/**
* Sets the size of the icon for a marker
- * @param {String} iconSize The array size in pixels of the marker image
+ * @param {Array} iconSize The array size in pixels of the marker image: [ width, height ]
*/
Marker.prototype.setIconSize = function(iconSize){
if(iconSize) {
@@ -1629,7 +1573,7 @@ Marker.prototype.setIconSize = function(iconSize){
/**
* Sets the anchor point for a marker
- * @param {String} iconAnchor The array offset of the anchor point
+ * @param {Array} iconAnchor The array offset in pixels of the anchor point from top left: [ right, down ]
*/
Marker.prototype.setIconAnchor = function(iconAnchor){
if(iconAnchor) {
View
168 build/2.0.12/mxn.geocommons.core.js
@@ -1,87 +1,55 @@
-/*
-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', {
+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) {
+ 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({
+
+ this.maps[api] = 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++) {
+ map_id: 143049,
+ uiLayers: false,
+ flashvars: {},
+ onMapLoaded: function(map){
+ me.loaded[me.api] = true;
+ var num_events = me.onload[me.api].length;
+ for (var i = 0; i < num_events; i++) {
me.onload[me.api][i]();
}
+ me.load.fire();
+ },
+ onMapPanStop: function() {
+ me.endPan.fire();
+ },
+ onMapZoomed: function() {
+ me.changeZoom.fire();
+ },
+ onFeatureSelected: function() {
+ me.click.fire();
}
+
});
- },
+ },
applyOptions: function(){
var map = this.maps[this.api];
// TODO: Add provider code
},
- resizeTo: function(width, height){
+ 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");
+ map.setMapStyle({zoom: {visible: args.zoom || false, expanded: (args.zoom == 'large')}});
+ map.setMapStyle({layers: {visible: args.layers || false}});
+ map.setMapStyle({legend: {visible: args.legend || false, expanded: true}});
},
addSmallControls: function() {
@@ -90,8 +58,7 @@ mxn.register('geocommons', {
zoom: 'small',
legend: "open"
});
- // showControl("Zoom", args.zoom);
- // showControl("Legend", args.legend, "open");
+
},
addLargeControls: function() {
@@ -115,7 +82,7 @@ mxn.register('geocommons', {
// TODO: Add provider code
},
- setCenterAndZoom: function(point, zoom) {
+ setCenterAndZoom: function(point, zoom) {
var map = this.maps[this.api];
map.setCenterZoom(point.lat, point.lon,zoom);
},
@@ -128,7 +95,7 @@ mxn.register('geocommons', {
setCenter: function(point, options) {
var map = this.maps[this.api];
- map.setCenter(point.lat, point.lon);
+ map.setCenter(point.lat, point.lon);
},
setZoom: function(zoom) {
@@ -157,34 +124,38 @@ mxn.register('geocommons', {
var map = this.maps[this.api];
switch(type) {
case mxn.Mapstraction.ROAD:
- map.setMapProvider("OpenStreetMap (road)");
- break;
+ map.setBasemap("openstreetmap");
+ break;
case mxn.Mapstraction.SATELLITE:
- map.setMapProvider("BlueMarble");
- break;
+ map.setBasemap("nasabluemarble");
+ break;
+ case mxn.Mapstraction.TERRAIN:
+ map.setBasemap("acetateterrain");
+ break;
case mxn.Mapstraction.HYBRID:
- map.setMapProvider("Google Hybrid");
- break;
+ map.setBasemap("googlehybrid");
+ break;
default:
- map.setMapProvider(type);
- }
+ map.setBasemap(type);
+ }
},
getMapType: function() {
var map = this.maps[this.api];
// TODO: I don't thick this is correct -Derek
- switch(map.getMapProvider()) {
- case "OpenStreetMap (road)":
+ switch(map.getBasemap().name) {
+ case "openstreetmap":
return mxn.Mapstraction.ROAD;
- case "BlueMarble":
+ case "nasabluemarble":
return mxn.Mapstraction.SATELLITE;
- case "Google Hybrid":
+ case "acetateterrain":
+ return mxn.Mapstraction.TERRAIN;
+ case "googlehybrid":
return mxn.Mapstraction.HYBRID;
default:
return null;
- }
-
+ }
},
getBounds: function () {
@@ -197,7 +168,7 @@ mxn.register('geocommons', {
var map = this.maps[this.api];
var sw = bounds.getSouthWest();
var ne = bounds.getNorthEast();
- map.setExtent(ne.lat,sw.lat,ne.lon,sw.lon);
+ map.setExtent(sw.lon,sw.lat,ne.lon,ne.lat);
},
@@ -228,31 +199,44 @@ mxn.register('geocommons', {
addTileLayer: function(tile_url, opacity, copyright_text, min_zoom, max_zoom) {
var map = this.maps[this.api];
- // TODO: Add provider code
+ map.addLayer({source: "tile:" + tile_url, styles: {fill: {opacity: opacity || 1.0}}});
},
toggleTileLayer: function(tile_url) {
var map = this.maps[this.api];
- // TODO: Add provider code
+ var layers = map.getLayers();
+ for(var i = 0; i < layers.length; ++i) {
+ if(layers[i].source == "tile:" + tile_url) {
+ map.showLayer(layers[i].guid, !layers[i].visible);
+ }
+ }
},
getPixelRatio: function() {
var map = this.maps[this.api];
- // TODO: Add provider code
+ // TODO: Add provider code
},
mousePosition: function(element) {
var map = this.maps[this.api];
- // TODO: Add provider code
+ // 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);
+ var layers = map.getLayers();
+ for(var i = 0; i < layers.length; ++i) {
+ if(layers[i].title == "Edit Layer") {
+ map.addFeatures(layers[i].guid, [pin], false);
+ map.addLayerInfoWindowFilter(layers[i].guid, {title: "$[title]", tabs: [{type: "text", title: "About", value: "$[infoBubble]"}]})
+ }
+ }
+
return pin;
},
@@ -271,7 +255,7 @@ mxn.register('geocommons', {
addPolyline: function(polyline, old) {
var map = this.maps[this.api];
var pl = polyline.toProprietary(this.api);
- // TODO: Add provider code
+ // TODO: Add provider code
// map.addOverlay(pl);
return pl;
},
@@ -286,26 +270,30 @@ mxn.register('geocommons', {
LatLonPoint: {
toProprietary: function() {
- // TODO: Add provider code
- return {};
+ // GeoJSON
+ return {type: "Point", coordinates: [this.lon,this.lat]};
},
- fromProprietary: function(googlePoint) {
- // TODO: Add provider code
+ fromProprietary: function(point) {
+ this.lon = point.coordinates[0];
+ this.lat = point.coordinates[1];
}
},
Marker: {
toProprietary: function() {
- // TODO: Add provider code
- return {};
+ return {title: this.labelText || "", infoBubble: this.infoBubble || "", geometry: this.location.toProprietary('geocommons')};
},
- openBubble: function() {
+ openBubble: function() {
// TODO: Add provider code
},
+ closeBubble: function() {
+ // TODO: Add provider code
+ },
+
hide: function() {
// TODO: Add provider code
View
34 build/2.0.12/mxn.js
@@ -1,15 +1,3 @@
-/*
-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
@@ -257,7 +245,7 @@ mxn.Invoker = function(aobj, asClassName, afnApiIdGetter){
this.go = function(sMethodName, args, oOptions){
// make sure args is an array
- args = Array.prototype.slice.apply(args);
+ args = typeof(args) != 'undefined' ? Array.prototype.slice.apply(args) : [];
if(typeof(oOptions) == 'undefined'){
oOptions = defOpts;
@@ -304,7 +292,7 @@ mxn.util = {
merge: function(oRecv, oGive){
for (var sPropName in oGive){
if (oGive.hasOwnProperty(sPropName)) {
- if(!oRecv.hasOwnProperty(sPropName)){
+ if(!oRecv.hasOwnProperty(sPropName) || typeof(oRecv[sPropName]) !== 'object' || typeof(oGive[sPropName]) !== 'object'){
oRecv[sPropName] = oGive[sPropName];
}
else {
@@ -499,14 +487,28 @@ mxn.util = {
*/
stringFormat: function(strIn){
var replaceRegEx = /\{\d+\}/g;
- var args = Array.slice.apply(arguments);
+ var args = Array.prototype.slice.apply(arguments);
args.shift();
return strIn.replace(replaceRegEx, function(strVal){
var num = strVal.slice(1, -1);
return args[num];
});
- }
+ },
+ /**
+ * Traverses an object graph using a series of map functions provided as arguments
+ * 2 to n. Map functions are only called if the working object is not undefined/null.
+ * For usage see mxn.google.geocoder.js.
+ */
+ traverse: function(start) {
+ var args = Array.prototype.slice.apply(arguments);
+ args.shift();
+ var working = start;
+ while(typeof(working) != 'undefined' && working !== null && args.length > 0){
+ var op = args.shift();
+ working = op(working);
+ }
+ }
};
/**
View
207 build/2.0.13/mxn.core.js
@@ -49,6 +49,11 @@ var Mapstraction = mxn.Mapstraction = function(element, api, debug) {
this.eventListeners = [];
/**
+ * The array of all layers that have been added to the map.
+ */
+ this.tileLayers = [];
+
+ /**
* The markers currently loaded.
* @name mxn.Mapstraction#markers
* @property
@@ -126,7 +131,7 @@ var Mapstraction = mxn.Mapstraction = function(element, api, debug) {
'changeZoom',
/**
- * Marker is removed {marker: Marker}
+ * Marker is added {marker: Marker}
* @name mxn.Mapstraction#markerAdded
* @event
*/
@@ -226,6 +231,7 @@ mxn.addProxyMethods(Mapstraction, [
* mxn.Mapstraction.ROAD
* mxn.Mapstraction.SATELLITE
* mxn.Mapstraction.HYBRID
+ * mxn.Mapstraction.PHYSICAL
* @name mxn.Mapstraction#getMapType
* @function
* @returns {Number}
@@ -310,6 +316,7 @@ mxn.addProxyMethods(Mapstraction, [
* mxn.Mapstraction.ROAD
* mxn.Mapstraction.SATELLITE
* mxn.Mapstraction.HYBRID
+ * mxn.Mapstraction.PHYSICAL
* @name mxn.Mapstraction#setMapType
* @function
* @param {Number} type
@@ -733,43 +740,40 @@ Mapstraction.prototype.removeAllPolylines = function() {
}
};
-/**
- * autoCenterAndZoom sets the center and zoom of the map to the smallest bounding box
- * containing all markers
- */
-Mapstraction.prototype.autoCenterAndZoom = function() {
- var lat_max = -90;
- var lat_min = 90;
- var lon_max = -180;
- var lon_min = 180;
- var lat, lon;
- var checkMinMax = function(){
- if (lat > lat_max) {
- lat_max = lat;
- }
- if (lat < lat_min) {
- lat_min = lat;
- }
- if (lon > lon_max) {
- lon_max = lon;
- }
- if (lon < lon_min) {
- lon_min = lon;
+var collectPoints = function(bMarkers, bPolylines, predicate) {
+ var points = [];
+
+ if (bMarkers) {
+ for (var i = 0; i < this.markers.length; i++) {
+ var mark = this.markers[i];
+ if (!predicate || predicate(mark)) {
+ points.push(mark.location);
+ }
}
- };
- for (var i = 0; i < this.markers.length; i++) {
- lat = this.markers[i].location.lat;
- lon = this.markers[i].location.lon;
- checkMinMax();
}
- for(i = 0; i < this.polylines.length; i++) {
- for (var j = 0; j < this.polylines[i].points.length; j++) {
- lat = this.polylines[i].points[j].lat;
- lon = this.polylines[i].points[j].lon;
- checkMinMax();
+
+ if (bPolylines) {
+ for(i = 0; i < this.polylines.length; i++) {
+ var poly = this.polylines[i];
+ if (!predicate || predicate(poly)) {
+ for (var j = 0; j < poly.points.length; j++) {
+ points.push(poly.points[j]);
+ }
+ }
}
}
- this.setBounds( new BoundingBox(lat_min, lon_min, lat_max, lon_max) );
+
+ return points;
+};
+
+/**
+ * Sets the center and zoom of the map to the smallest bounding box
+ * containing all markers and polylines
+ */
+Mapstraction.prototype.autoCenterAndZoom = function() {
+ var points = collectPoints.call(this, true, true);
+
+ this.centerAndZoomOnPoints(points);
};
/**
@@ -778,12 +782,13 @@ Mapstraction.prototype.autoCenterAndZoom = function() {
* This is useful if you don't want to have to add markers to the map
*/
Mapstraction.prototype.centerAndZoomOnPoints = function(points) {
- var bounds = new BoundingBox(points[0].lat,points[0].lon,points[0].lat,points[0].lon);
+ var bounds = new BoundingBox(90, 180, -90, -180);
- for (var i=1, len = points.length ; i<len; i++) {
+ for (var i = 0, len = points.length; i < len; i++) {
bounds.extend(points[i]);
}
+ console.log(bounds)
this.setBounds(bounds);
};
@@ -793,88 +798,43 @@ Mapstraction.prototype.centerAndZoomOnPoints = function(points) {
* will only include markers and polylines with an attribute of "visible"
*/
Mapstraction.prototype.visibleCenterAndZoom = function() {
- var lat_max = -90;
- var lat_min = 90;
- var lon_max = -180;
- var lon_min = 180;
- var lat, lon;
- var checkMinMax = function(){
- if (lat > lat_max) {
- lat_max = lat;
- }
- if (lat < lat_min) {
- lat_min = lat;
- }
- if (lon > lon_max) {
- lon_max = lon;
- }
- if (lon < lon_min) {
- lon_min = lon;
- }
+ var predicate = function(obj) {
+ return obj.getAttribute("visible");
};
- for (var i=0; i<this.markers.length; i++) {
- if (this.markers[i].getAttribute("visible")) {
- lat = this.markers[i].location.lat;
- lon = this.markers[i].location.lon;
- checkMinMax();
- }
- }
-
- for (i=0; i<this.polylines.length; i++){
- if (this.polylines[i].getAttribute("visible")) {
- for (j=0; j<this.polylines[i].points.length; j++) {
- lat = this.polylines[i].points[j].lat;
- lon = this.polylines[i].points[j].lon;
- checkMinMax();
- }
- }
- }
-
- this.setBounds(new BoundingBox(lat_min, lon_min, lat_max, lon_max));
+ var points = collectPoints.call(this, true, true, predicate);
+
+ this.centerAndZoomOnPoints(points);
};
/**
* Automatically sets center and zoom level to show all polylines
- * Takes into account radious of polyline
- * @param {Int} radius
+ * @param {Number} padding Optional number of kilometers to pad around polyline
*/
-Mapstraction.prototype.polylineCenterAndZoom = function(radius) {
- var lat_max = -90;
- var lat_min = 90;
- var lon_max = -180;
- var lon_min = 180;
-
- for (var i=0; i < mapstraction.polylines.length; i++)
- {
- for (var j=0; j<mapstraction.polylines[i].points.length; j++)
- {
- lat = mapstraction.polylines[i].points[j].lat;
- lon = mapstraction.polylines[i].points[j].lon;
-
- latConv = lonConv = radius;
-
- if (radius > 0)
- {
- latConv = (radius / mapstraction.polylines[i].points[j].latConv());
- lonConv = (radius / mapstraction.polylines[i].points[j].lonConv());
- }
-
- if ((lat + latConv) > lat_max) {
- lat_max = (lat + latConv);
- }
- if ((lat - latConv) < lat_min) {
- lat_min = (lat - latConv);
- }
- if ((lon + lonConv) > lon_max) {
- lon_max = (lon + lonConv);
- }
- if ((lon - lonConv) < lon_min) {
- lon_min = (lon - lonConv);
- }
+Mapstraction.prototype.polylineCenterAndZoom = function(padding) {
+ padding = padding || 0;
+
+ var points = collectPoints.call(this, false, true);
+
+ if (padding > 0) {
+ var padPoints = [];
+ for (var i = 0; i < points.length; i++) {
+ var point = points[i];
+
+ var kmInOneDegreeLat = point.latConv();
+ var kmInOneDegreeLon = point.lonConv();
+
+ var latPad = padding / kmInOneDegreeLat;
+ var lonPad = padding / kmInOneDegreeLon;
+
+ var ne = new LatLonPoint(point.lat + latPad, point.lon + lonPad);
+ var sw = new LatLonPoint(point.lat - latPad, point.lon - lonPad);
+
+ padPoints.push(ne, sw);
}
+ points = points.concat(padPoints);
}
-
- this.setBounds(new BoundingBox(lat_min, lon_min, lat_max, lon_max));
+
+ this.centerAndZoomOnPoints(points);
};
/**
@@ -1032,7 +992,6 @@ Mapstraction.prototype.addTileLayer = function(tile_url, opacity, copyright_text
return;
}
- this.tileLayers = this.tileLayers || [];
opacity = opacity || 0.6;
copyright_text = copyright_text || "Mapstraction";
min_zoom = min_zoom || 1;
@@ -1242,13 +1201,10 @@ Mapstraction.prototype.getMap = function() {
* @param {double} lon is the longitude
* @exports LatLonPoint as mxn.LatLonPoint
*/
-var LatLonPoint = mxn.LatLonPoint = function(lat, lon) {
- // TODO error if undefined?
- // if (lat == undefined) alert('undefined lat');
- // if (lon == undefined) alert('undefined lon');
- this.lat = lat;
- this.lon = lon;
- this.lng = lon; // lets be lon/lng agnostic
+var LatLonPoint = mxn.LatLonPoint = function(lat, lon) {
+ this.lat = Number(lat); // force to be numeric
+ this.lon = Number(lon);
+ this.lng = this.lon; // lets be lon/lng agnostic
this.invoker = new mxn.Invoker(this, 'LatLonPoint');
};
@@ -1344,7 +1300,6 @@ LatLonPoint.prototype.lonConv = function() {
*/
var BoundingBox = mxn.BoundingBox = function(swlat, swlon, nelat, nelon) {
//FIXME throw error if box bigger than world
- //alert('new bbox ' + swlat + ',' + swlon + ',' + nelat + ',' + nelon);
this.sw = new LatLonPoint(swlat, swlon);
this.ne = new LatLonPoint(nelat, nelon);
};
@@ -1395,20 +1350,22 @@ BoundingBox.prototype.toSpan = function() {
return new LatLonPoint( Math.abs(this.sw.lat - this.ne.lat), Math.abs(this.sw.lon - this.ne.lon) );
};
+
+
/**
* extend extends the bounding box to include the new point
*/
BoundingBox.prototype.extend = function(point) {
- if(this.sw.lat > point.lat) {
+ if (this.sw.lat > point.lat) {
this.sw.lat = point.lat;
}
- if(this.sw.lon > point.lon) {
+ if (this.sw.lon > point.lon) {
this.sw.lon = point.lon;
}
- if(this.ne.lat < point.lat) {
+ if (this.ne.lat < point.lat) {
this.ne.lat = point.lat;
}
- if(this.ne.lon < point.lon) {
+ if (this.ne.lon < point.lon) {
this.ne.lon = point.lon;
}
return;
@@ -1606,7 +1563,7 @@ Marker.prototype.setIcon = function(iconUrl, iconSize, iconAnchor) {
/**
* Sets the size of the icon for a marker
- * @param {String} iconSize The array size in pixels of the marker image
+ * @param {Array} iconSize The array size in pixels of the marker image: [ width, height ]
*/
Marker.prototype.setIconSize = function(iconSize){
if(iconSize) {
@@ -1616,7 +1573,7 @@ Marker.prototype.setIconSize = function(iconSize){
/**
* Sets the anchor point for a marker
- * @param {String} iconAnchor The array offset of the anchor point
+ * @param {Array} iconAnchor The array offset in pixels of the anchor point from top left: [ right, down ]
*/
Marker.prototype.setIconAnchor = function(iconAnchor){
if(iconAnchor) {
View
156 build/2.0.13/mxn.geocommons.core.js
@@ -1,75 +1,55 @@
-mxn.register('geocommons', {
+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) {
+ 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({
+
+ this.maps[api] = 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++) {
+ map_id: 143049,
+ uiLayers: false,
+ flashvars: {},
+ onMapLoaded: function(map){
+ me.loaded[me.api] = true;
+ var num_events = me.onload[me.api].length;
+ for (var i = 0; i < num_events; i++) {
me.onload[me.api][i]();
}
+ me.load.fire();
+ },
+ onMapPanStop: function() {
+ me.endPan.fire();
+ },
+ onMapZoomed: function() {
+ me.changeZoom.fire();
+ },
+ onFeatureSelected: function() {
+ me.click.fire();
}
+
});
- },
+ },
applyOptions: function(){
var map = this.maps[this.api];
// TODO: Add provider code
},
- resizeTo: function(width, height){
+ 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");
+ map.setMapStyle({zoom: {visible: args.zoom || false, expanded: (args.zoom == 'large')}});
+ map.setMapStyle({layers: {visible: args.layers || false}});
+ map.setMapStyle({legend: {visible: args.legend || false, expanded: true}});
},
addSmallControls: function() {
@@ -78,8 +58,7 @@ mxn.register('geocommons', {
zoom: 'small',
legend: "open"
});
- // showControl("Zoom", args.zoom);
- // showControl("Legend", args.legend, "open");
+
},
addLargeControls: function() {
@@ -103,7 +82,7 @@ mxn.register('geocommons', {
// TODO: Add provider code
},
- setCenterAndZoom: function(point, zoom) {
+ setCenterAndZoom: function(point, zoom) {
var map = this.maps[this.api];
map.setCenterZoom(point.lat, point.lon,zoom);
},
@@ -116,7 +95,7 @@ mxn.register('geocommons', {
setCenter: function(point, options) {
var map = this.maps[this.api];
- map.setCenter(point.lat, point.lon);
+ map.setCenter(point.lat, point.lon);
},
setZoom: function(zoom) {
@@ -145,34 +124,38 @@ mxn.register('geocommons', {
var map = this.maps[this.api];
switch(type) {
case mxn.Mapstraction.ROAD:
- map.setMapProvider("OpenStreetMap (road)");
- break;
+ map.setBasemap("openstreetmap");
+ break;
case mxn.Mapstraction.SATELLITE:
- map.setMapProvider("BlueMarble");
- break;
+ map.setBasemap("nasabluemarble");
+ break;
+ case mxn.Mapstraction.TERRAIN:
+ map.setBasemap("acetateterrain");
+ break;
case mxn.Mapstraction.HYBRID:
- map.setMapProvider("Google Hybrid");
- break;
+ map.setBasemap("googlehybrid");
+ break;
default:
- map.setMapProvider(type);
- }
+ map.setBasemap(type);
+ }
},
getMapType: function() {
var map = this.maps[this.api];
// TODO: I don't thick this is correct -Derek
- switch(map.getMapProvider()) {
- case "OpenStreetMap (road)":
+ switch(map.getBasemap().name) {
+ case "openstreetmap":
return mxn.Mapstraction.ROAD;
- case "BlueMarble":
+ case "nasabluemarble":
return mxn.Mapstraction.SATELLITE;
- case "Google Hybrid":
+ case "acetateterrain":
+ return mxn.Mapstraction.TERRAIN;
+ case "googlehybrid":
return mxn.Mapstraction.HYBRID;
default:
return null;
- }
-
+ }
},
getBounds: function () {
@@ -185,7 +168,7 @@ mxn.register('geocommons', {
var map = this.maps[this.api];
var sw = bounds.getSouthWest();
var ne = bounds.getNorthEast();
- map.setExtent(ne.lat,sw.lat,ne.lon,sw.lon);
+ map.setExtent(sw.lon,sw.lat,ne.lon,ne.lat);
},
@@ -216,31 +199,44 @@ mxn.register('geocommons', {
addTileLayer: function(tile_url, opacity, copyright_text, min_zoom, max_zoom) {
var map = this.maps[this.api];
- // TODO: Add provider code
+ map.addLayer({source: "tile:" + tile_url, styles: {fill: {opacity: opacity || 1.0}}});
},
toggleTileLayer: function(tile_url) {
var map = this.maps[this.api];
- // TODO: Add provider code
+ var layers = map.getLayers();
+ for(var i = 0; i < layers.length; ++i) {
+ if(layers[i].source == "tile:" + tile_url) {
+ map.showLayer(layers[i].guid, !layers[i].visible);
+ }
+ }
},
getPixelRatio: function() {
var map = this.maps[this.api];
- // TODO: Add provider code
+ // TODO: Add provider code
},
mousePosition: function(element) {
var map = this.maps[this.api];
- // TODO: Add provider code
+ // 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);
+ var layers = map.getLayers();
+ for(var i = 0; i < layers.length; ++i) {
+ if(layers[i].title == "Edit Layer") {
+ map.addFeatures(layers[i].guid, [pin], false);
+ map.addLayerInfoWindowFilter(layers[i].guid, {title: "$[title]", tabs: [{type: "text", title: "About", value: "$[infoBubble]"}]})
+ }
+ }
+
return pin;
},
@@ -259,7 +255,7 @@ mxn.register('geocommons', {
addPolyline: function(polyline, old) {
var map = this.maps[this.api];
var pl = polyline.toProprietary(this.api);
- // TODO: Add provider code
+ // TODO: Add provider code
// map.addOverlay(pl);
return pl;
},
@@ -274,26 +270,30 @@ mxn.register('geocommons', {
LatLonPoint: {
toProprietary: function() {
- // TODO: Add provider code
- return {};
+ // GeoJSON
+ return {type: "Point", coordinates: [this.lon,this.lat]};
},
- fromProprietary: function(googlePoint) {
- // TODO: Add provider code
+ fromProprietary: function(point) {
+ this.lon = point.coordinates[0];
+ this.lat = point.coordinates[1];
}
},
Marker: {
toProprietary: function() {
- // TODO: Add provider code
- return {};
+ return {title: this.labelText || "", infoBubble: this.infoBubble || "", geometry: this.location.toProprietary('geocommons')};
},
- openBubble: function() {
+ openBubble: function() {
// TODO: Add provider code
},
+ closeBubble: function() {
+ // TODO: Add provider code
+ },
+
hide: function() {
// TODO: Add provider code
View
22 build/2.0.13/mxn.js
@@ -245,7 +245,7 @@ mxn.Invoker = function(aobj, asClassName, afnApiIdGetter){
this.go = function(sMethodName, args, oOptions){
// make sure args is an array
- args = Array.prototype.slice.apply(args);
+ args = typeof(args) != 'undefined' ? Array.prototype.slice.apply(args) : [];
if(typeof(oOptions) == 'undefined'){
oOptions = defOpts;
@@ -292,7 +292,7 @@ mxn.util = {
merge: function(oRecv, oGive){
for (var sPropName in oGive){
if (oGive.hasOwnProperty(sPropName)) {
- if(!oRecv.hasOwnProperty(sPropName)){
+ if(!oRecv.hasOwnProperty(sPropName) || typeof(oRecv[sPropName]) !== 'object' || typeof(oGive[sPropName]) !== 'object'){
oRecv[sPropName] = oGive[sPropName];
}
else {
@@ -487,14 +487,28 @@ mxn.util = {
*/
stringFormat: function(strIn){
var replaceRegEx = /\{\d+\}/g;
- var args = Array.slice.apply(arguments);
+ var args = Array.prototype.slice.apply(arguments);
args.shift();
return strIn.replace(replaceRegEx, function(strVal){
var num = strVal.slice(1, -1);
return args[num];
});
- }
+ },
+ /**
+ * Traverses an object graph using a series of map functions provided as arguments
+ * 2 to n. Map functions are only called if the working object is not undefined/null.
+ * For usage see mxn.google.geocoder.js.
+ */
+ traverse: function(start) {
+ var args = Array.prototype.slice.apply(arguments);
+ args.shift();
+ var working = start;
+ while(typeof(working) != 'undefined' && working !== null && args.length > 0){
+ var op = args.shift();
+ working = op(working);
+ }
+ }
};
/**
View
23 build/2.0.14/mxn.cloudmade.core.js
@@ -1,15 +1,3 @@
-/*
-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('cloudmade', {
Mapstraction: {
@@ -50,9 +38,12 @@ mxn.register('cloudmade', {
applyOptions: function(){
var map = this.maps[this.api];
- if(this.options.enableScrollWheelZoom){
+ if (this.options.enableScrollWheelZoom) {
map.enableScrollWheelZoom();
}
+ else {
+ map.disableScrollWheelZoom();
+ }
},
resizeTo: function(width, height){
@@ -266,13 +257,13 @@ mxn.register('cloudmade', {
getPixelRatio: function() {
var map = this.maps[this.api];
- // TODO: Add provider code
+ // TODO: Add provider code
},
mousePosition: function(element) {
var map = this.maps[this.api];
- // TODO: Add provider code
+ // TODO: Add provider code
}
},
@@ -358,7 +349,7 @@ mxn.register('cloudmade', {
}
if (this.closed || pts[0].equals(pts[pts.length-1])) {
poly = new CM.Polygon(pts, this.color, this.width, this.opacity, this.fillColor || "#5462E3", this.opacity || "0.3");
- }
+ }
else {
poly = new CM.Polyline(pts, this.color, this.width, this.opacity);
}
View
218 build/2.0.14/mxn.core.js
@@ -1,15 +1,3 @@
-/*
-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.
-*/
(function(){
/**
@@ -61,6 +49,11 @@ var Mapstraction = mxn.Mapstraction = function(element, api, debug) {
this.eventListeners = [];
/**
+ * The array of all layers that have been added to the map.
+ */
+ this.tileLayers = [];
+
+ /**
* The markers currently loaded.
* @name mxn.Mapstraction#markers
* @property
@@ -138,7 +131,7 @@ var Mapstraction = mxn.Mapstraction = function(element, api, debug) {
'changeZoom',
/**
- * Marker is removed {marker: Marker}
+ * Marker is added {marker: Marker}
* @name mxn.Mapstraction#markerAdded
* @event
*/
@@ -238,6 +231,7 @@ mxn.addProxyMethods(Mapstraction, [
* mxn.Mapstraction.ROAD
* mxn.Mapstraction.SATELLITE
* mxn.Mapstraction.HYBRID
+ * mxn.Mapstraction.PHYSICAL
* @name mxn.Mapstraction#getMapType
* @function
* @returns {Number}
@@ -322,6 +316,7 @@ mxn.addProxyMethods(Mapstraction, [
* mxn.Mapstraction.ROAD
* mxn.Mapstraction.SATELLITE
* mxn.Mapstraction.HYBRID
+ * mxn.Mapstraction.PHYSICAL
* @name mxn.Mapstraction#setMapType
* @function
* @param {Number} type
@@ -745,43 +740,40 @@ Mapstraction.prototype.removeAllPolylines = function() {
}
};
-/**
- * autoCenterAndZoom sets the center and zoom of the map to the smallest bounding box
- * containing all markers
- */
-Mapstraction.prototype.autoCenterAndZoom = function() {
- var lat_max = -90;
- var lat_min = 90;
- var lon_max = -180;
- var lon_min = 180;
- var lat, lon;
- var checkMinMax = function(){
- if (lat > lat_max) {
- lat_max = lat;
- }
- if (lat < lat_min) {
- lat_min = lat;
- }
- if (lon > lon_max) {
- lon_max = lon;
- }
- if (lon < lon_min) {
- lon_min = lon;
+var collectPoints = function(bMarkers, bPolylines, predicate) {
+ var points = [];
+
+ if (bMarkers) {
+ for (var i = 0; i < this.markers.length; i++) {
+ var mark = this.markers[i];
+ if (!predicate || predicate(mark)) {
+ points.push(mark.location);
+ }
}
- };
- for (var i = 0; i < this.markers.length; i++) {
- lat = this.markers[i].location.lat;
- lon = this.markers[i].location.lon;
- checkMinMax();
}
- for(i = 0; i < this.polylines.length; i++) {
- for (var j = 0; j < this.polylines[i].points.length; j++) {
- lat = this.polylines[i].points[j].lat;
- lon = this.polylines[i].points[j].lon;
- checkMinMax();
+
+ if (bPolylines) {
+ for(i = 0; i < this.polylines.length; i++) {
+ var poly = this.polylines[i];
+ if (!predicate || predicate(poly)) {
+ for (var j = 0; j < poly.points.length; j++) {
+ points.push(poly.points[j]);
+ }
+ }
}
}
- this.setBounds( new BoundingBox(lat_min, lon_min, lat_max, lon_max) );
+
+ return points;
+};
+
+/**
+ * Sets the center and zoom of the map to the smallest bounding box
+ * containing all markers and polylines
+ */
+Mapstraction.prototype.autoCenterAndZoom = function() {
+ var points = collectPoints.call(this, true, true);
+
+ this.centerAndZoomOnPoints(points);
};
/**
@@ -790,9 +782,9 @@ Mapstraction.prototype.autoCenterAndZoom = function() {
* This is useful if you don't want to have to add markers to the map
*/
Mapstraction.prototype.centerAndZoomOnPoints = function(points) {
- var bounds = new BoundingBox(points[0].lat,points[0].lon,points[0].lat,points[0].lon);
+ var bounds = new BoundingBox(90, 180, -90, -180);
- for (var i=1, len = points.length ; i<len; i++) {
+ for (var i = 0, len = points.length; i < len; i++) {
bounds.extend(points[i]);
}
@@ -805,88 +797,43 @@ Mapstraction.prototype.centerAndZoomOnPoints = function(points) {
* will only include markers and polylines with an attribute of "visible"
*/
Mapstraction.prototype.visibleCenterAndZoom = function() {
- var lat_max = -90;
- var lat_min = 90;
- var lon_max = -180;
- var lon_min = 180;
- var lat, lon;
- var checkMinMax = function(){
- if (lat > lat_max) {
- lat_max = lat;
- }
- if (lat < lat_min) {
- lat_min = lat;
- }
- if (lon > lon_max) {
- lon_max = lon;
- }
- if (lon < lon_min) {
- lon_min = lon;
- }
+ var predicate = function(obj) {
+ return obj.getAttribute("visible");
};
- for (var i=0; i<this.markers.length; i++) {
- if (this.markers[i].getAttribute("visible")) {
- lat = this.markers[i].location.lat;
- lon = this.markers[i].location.lon;
- checkMinMax();
- }
- }
-
- for (i=0; i<this.polylines.length; i++){
- if (this.polylines[i].getAttribute("visible")) {
- for (j=0; j<this.polylines[i].points.length; j++) {
- lat = this.polylines[i].points[j].lat;
- lon = this.polylines[i].points[j].lon;
- checkMinMax();
- }
- }
- }
-
- this.setBounds(new BoundingBox(lat_min, lon_min, lat_max, lon_max));
+ var points = collectPoints.call(this, true, true, predicate);
+
+ this.centerAndZoomOnPoints(points);
};
/**
* Automatically sets center and zoom level to show all polylines
- * Takes into account radious of polyline
- * @param {Int} radius
+ * @param {Number} padding Optional number of kilometers to pad around polyline
*/
-Mapstraction.prototype.polylineCenterAndZoom = function(radius) {
- var lat_max = -90;
- var lat_min = 90;
- var lon_max = -180;
- var lon_min = 180;
-
- for (var i=0; i < mapstraction.polylines.length; i++)
- {
- for (var j=0; j<mapstraction.polylines[i].points.length; j++)
- {
- lat = mapstraction.polylines[i].points[j].lat;
- lon = mapstraction.polylines[i].points[j].lon;
-
- latConv = lonConv = radius;
-
- if (radius > 0)
- {
- latConv = (radius / mapstraction.polylines[i].points[j].latConv());
- lonConv = (radius / mapstraction.polylines[i].points[j].lonConv());
- }
-
- if ((lat + latConv) > lat_max) {
- lat_max = (lat + latConv);
- }
- if ((lat - latConv) < lat_min) {
- lat_min = (lat - latConv);
- }
- if ((lon + lonConv) > lon_max) {
- lon_max = (lon + lonConv);
- }
- if ((lon - lonConv) < lon_min) {
- lon_min = (lon - lonConv);
- }
+Mapstraction.prototype.polylineCenterAndZoom = function(padding) {
+ padding = padding || 0;
+
+ var points = collectPoints.call(this, false, true);
+
+ if (padding > 0) {
+ var padPoints = [];
+ for (var i = 0; i < points.length; i++) {
+ var point = points[i];
+
+ var kmInOneDegreeLat = point.latConv();
+ var kmInOneDegreeLon = point.lonConv();
+
+ var latPad = padding / kmInOneDegreeLat;
+ var lonPad = padding / kmInOneDegreeLon;
+
+ var ne = new LatLonPoint(point.lat + latPad, point.lon + lonPad);
+ var sw = new LatLonPoint(point.lat - latPad, point.lon - lonPad);
+
+ padPoints.push(ne, sw);
}
+ points = points.concat(padPoints);
}
-
- this.setBounds(new BoundingBox(lat_min, lon_min, lat_max, lon_max));
+
+ this.centerAndZoomOnPoints(points);
};
/**
@@ -1044,7 +991,6 @@ Mapstraction.prototype.addTileLayer = function(tile_url, opacity, copyright_text
return;
}
- this.tileLayers = this.tileLayers || [];
opacity = opacity || 0.6;
copyright_text = copyright_text || "Mapstraction";
min_zoom = min_zoom || 1;
@@ -1254,13 +1200,10 @@ Mapstraction.prototype.getMap = function() {
* @param {double} lon is the longitude
* @exports LatLonPoint as mxn.LatLonPoint
*/
-var LatLonPoint = mxn.LatLonPoint = function(lat, lon) {
- // TODO error if undefined?
- // if (lat == undefined) alert('undefined lat');
- // if (lon == undefined) alert('undefined lon');
- this.lat = lat;
- this.lon = lon;
- this.lng = lon; // lets be lon/lng agnostic
+var LatLonPoint = mxn.LatLonPoint = function(lat, lon) {
+ this.lat = Number(lat); // force to be numeric
+ this.lon = Number(lon);
+ this.lng = this.lon; // lets be lon/lng agnostic
this.invoker = new mxn.Invoker(this, 'LatLonPoint');
};
@@ -1356,7 +1299,6 @@ LatLonPoint.prototype.lonConv = function() {
*/
var BoundingBox = mxn.BoundingBox = function(swlat, swlon, nelat, nelon) {
//FIXME throw error if box bigger than world
- //alert('new bbox ' + swlat + ',' + swlon + ',' + nelat + ',' + nelon);
this.sw = new LatLonPoint(swlat, swlon);
this.ne = new LatLonPoint(nelat, nelon);
};
@@ -1407,20 +1349,22 @@ BoundingBox.prototype.toSpan = function() {
return new LatLonPoint( Math.abs(this.sw.lat - this.ne.lat), Math.abs(this.sw.lon - this.ne.lon) );
};
+
+
/**
* extend extends the bounding box to include the new point
*/
BoundingBox.prototype.extend = function(point) {
- if(this.sw.lat > point.lat) {
+ if (this.sw.lat > point.lat) {
this.sw.lat = point.lat;
}
- if(this.sw.lon > point.lon) {
+ if (this.sw.lon > point.lon) {
this.sw.lon = point.lon;
}
- if(this.ne.lat < point.lat) {
+ if (this.ne.lat < point.lat) {
this.ne.lat = point.lat;
}
- if(this.ne.lon < point.lon) {
+ if (this.ne.lon < point.lon) {
this.ne.lon = point.lon;
}
return;
@@ -1618,7 +1562,7 @@ Marker.prototype.setIcon = function(iconUrl, iconSize, iconAnchor) {
/**
* Sets the size of the icon for a marker
- * @param {String} iconSize The array size in pixels of the marker image
+ * @param {Array} iconSize The array size in pixels of the marker image: [ width, height ]
*/
Marker.prototype.setIconSize = function(iconSize){
if(iconSize) {
@@ -1628,7 +1572,7 @@ Marker.prototype.setIconSize = function(iconSize){
/**
* Sets the anchor point for a marker
- * @param {String} iconAnchor The array offset of the anchor point
+ * @param {Array} iconAnchor The array offset in pixels of the anchor point from top left: [ right, down ]
*/
Marker.prototype.setIconAnchor = function(iconAnchor){
if(iconAnchor) {
View
168 build/2.0.14/mxn.geocommons.core.js
@@ -1,87 +1,55 @@
-/*
-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', {
+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) {
+ 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({
+
+ this.maps[api] = new F1.Maker.Map({
dom_id: this.element.id,
- flashvars: {},