codesite-noreply at google.com
2009-Aug-24 02:47 UTC
[Mapstraction] [mapstraction] r19 committed - First pass at GeoCommons wrapper
Revision: 19 Author: ajturner Date: Sun Aug 23 19:46:44 2009 Log: First pass at GeoCommons wrapper http://code.google.com/p/mapstraction/source/detail?r=19 Added: /trunk/examples/index.html /trunk/source/mxn.geocommons.core.js Modified: /trunk/source/mxn.core.js ======================================--- /dev/null +++ /trunk/examples/index.html Sun Aug 23 19:46:44 2009 @@ -0,0 +1,57 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml"> +<head> + <title>Mapstraction Examples</title> + <script type="text/javascript" charset="utf-8" src="http://maker.codiv.dev.fortiusone.local/javascripts/embed.js"></script> + <script src="../source/mxn.js" type="text/javascript"></script> + <script src="../source/mxn.core.js" type="text/javascript"></script> + <script src="../source/mxn.geocommons.core.js" type="text/javascript"></script> + <style type="text/css"> + #mapstraction { + height: 400px; + width: 500px; + } + </style> +</head> +<body> + + <div id="mapstraction" style="position:relative; height: 400px; width:100%"></div> + <script type="text/javascript"> + // initialise the map with your choice of API + var mapstraction = new mxn.Mapstraction(''mapstraction'',''geocommons''); + mapstraction.addOverlay("4") + </script> + <div class=""> + <script type="text/javascript" charset="utf-8"> + + getCenter = function() { + var center = mapstraction.getCenter(); + alert(center.lat + " " + center.lon); + } + alertBounds = function() { + var bounds = mapstraction.getBounds(); + var sw = bounds.getSouthWest(); + var ne = bounds.getNorthEast(); + alert(sw.lat + " " + sw.lon + " " + ne.lat + " " + ne.lon); + } + +</script> +<h2>Demo Functions</h2> +<ul> + <li><a href="javascript:alert(''zoom is '' + mapstraction.getZoomLevelForBoundingBox(new mxn.BoundingBox(51.9,-4.3,52.25,-3.75)));">click me to get zoom for extent</a>.</li> + <li><a href="javascript:mapstraction.setBounds( new mxn.BoundingBox(51.9,-4.3,52.25,-3.75) );">click me to set bounds</a>.</li> + <li><a href="javascript:alertBounds();">click me to get bounds</a> </li> + <li><a href="javascript:mapstraction.setZoom( mapstraction.getZoom()-1 );">click me to decrement zoom</a>.</li> + <li><a href="javascript:mapstraction.setZoom( mapstraction.getZoom()+1 );">click me to increment zoom</a>.</li> + <li><a href="javascript:alert(''zoom is '' + mapstraction.getZoom());">click me to get zoom</a>.</li> + <li><a href="javascript:getCenter();">click me to getCenter</a>.</li> + <li><a href="javascript:mapstraction.setCenter(new mxn.LatLonPoint(52,0));">click me to setCenter</a>.</li> + <li><a href="javascript:mapstraction.setCenter(new mxn.LatLonPoint(38.404196,-123.008194), {pan: true});">click me to pan to center</a>.</li> + <li><a href="javascript:mapstraction.addControls({zoom:''small'', map_type:true});">click me to add controls</a>.</li> + <li><a href="javascript:mapstraction.resizeTo(''100px'',''200px'');">click me to resize</a>.</li> +</ul> + </div> + +</body> +</html> + ======================================--- /dev/null +++ /trunk/source/mxn.geocommons.core.js Sun Aug 23 19:46:44 2009 @@ -0,0 +1,233 @@ +mxn.register(''geocommons'', { + + Mapstraction: { + + init: function(element, api) { + var me = this; + this.element = element; + Maker.maker_host=''http://maker.recovery.geocommons.com''; + Maker.finder_host=''http://finder.recovery.geocommons.com''; + Maker.core_host=''http://recovery.geocommons.com''; + }, + + 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]; + showControl("Zoom", args.zoom); + showControl("Layers", args.layers); + showControl("Styles", args.styles); + showControl("Basemap", args.map_type); + showControl("Legend", args.legend, "open"); + // showControl("Legend", true, "close"); + }, + + addSmallControls: function() { + var map = this.maps[this.api]; + showControl("Zoom", args.zoom); + showControl("Legend", args.legend, "open"); + }, + + addLargeControls: function() { + var map = this.maps[this.api]; + showControl("Zoom", args.zoom); + showControl("Layers", args.layers); + showControl("Legend", args.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 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]; + switch(map.getMapProvider) { + case "OpenStreetMap (Road)": + retu + + } + // TODO: Add provider code + + //return mxn.Mapstraction.ROAD; + //return mxn.Mapstraction.SATELLITE; + //return mxn.Mapstraction.HYBRID; + + }, + + 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 + }, + + addOverlay: function(url, autoCenterAndZoom) { + var map = this.maps[this.api]; + var me = this; + Maker.load_map(this.element.id, url); + setTimeout(function() { me.maps[me.api] = swfobject.getObjectById(FlashMap.dom_id);}, 500); + }, + + 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() { + // TODO: Add provider code + }, + + fromProprietary: function(googlePoint) { + // TODO: Add provider code + } + + }, + + Marker: { + + toProprietary: function() { + // TODO: Add provider code + }, + + 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() { + // TODO: Add provider code + }, + + show: function() { + // TODO: Add provider code + }, + + hide: function() { + // TODO: Add provider code + } + + } + +}); ======================================--- /trunk/source/mxn.core.js Sun Aug 16 17:18:10 2009 +++ /trunk/source/mxn.core.js Sun Aug 23 19:46:44 2009 @@ -38,6 +38,7 @@ this.images = []; this.loaded = {}; this.onload = {}; + this.element = element; // option defaults this.options = {