Permalink
Browse files

removed corrections in core that were not standard across other platf…

…orms
  • Loading branch information...
davydotcom committed Feb 21, 2012
1 parent 9c72ed5 commit a82e5a73432a2453e630ef2ed858cb0de1bbb3b0
Showing with 189 additions and 56 deletions.
  1. +98 −0 examples/microsoft7.html
  2. +1 −3 source/mxn.core.js
  3. +25 −26 source/mxn.geocoder.js
  4. +19 −19 source/mxn.microsoft7.core.js
  5. +46 −8 source/mxn.openlayers.core.js
View
@@ -0,0 +1,98 @@
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<title>Mapstraction Examples - Microsoft7</title>
+ <script type="text/javascript" src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script>
+
+<script src="../source/mxn.js?(microsoft7,[geocoder])" type="text/javascript"></script>
+<style type="text/css">
+
+ #mapdiv {
+ height: 400px;
+ }
+
+</style>
+
+<script type="text/javascript">
+//<![CDATA[
+ var microsoft_key = "";
+ var mapstraction;
+ var geocoder;
+
+ function geocode_return(geocoded_location) {
+
+ // display the map centered on a latitude and longitude (Google zoom levels)
+ mapstraction.setCenterAndZoom(geocoded_location.point, 15);
+
+ // create a marker positioned at a lat/lon
+ var geocode_marker = new mxn.Marker(geocoded_location.point);
+
+ var address = geocoded_location.locality + ", " + geocoded_location.region;
+ geocode_marker.setInfoBubble(address);
+
+ // display marker
+ mapstraction.addMarker(geocode_marker);
+
+ // open the marker
+ geocode_marker.openBubble();
+ }
+
+ function initialize() {
+
+ // create mxn object
+ mapstraction = new mxn.Mapstraction('mapdiv','microsoft7');
+
+ mapstraction.addControls({
+ pan: true,
+ zoom: 'small',
+ map_type: true
+ });
+
+ var latlon = new mxn.LatLonPoint(18.47, -69.9);
+
+ mapstraction.setMapType(mxn.Mapstraction.SATELLITE);
+ mapstraction.setCenterAndZoom(latlon, 10);
+ mapstraction.mousePosition('position');
+
+ geocoder = new mxn.Geocoder('microsoft7',geocode_return);
+
+
+
+ // add a marker
+ var marker = new mxn.Marker(latlon);
+ mapstraction.addMarker(marker,true);
+
+ }
+
+ function user_submit() {
+ var address = {};
+ address.address = document.getElementById('address').value;
+ geocoder.geocode(address);
+ }
+
+ function changetohybrid(){
+ mapstraction.setMapType(mxn.Mapstraction.HYBRID);
+ }
+
+//]]>
+</script>
+
+</head>
+<body onload="initialize();">
+ <center>
+ <table border='1' width='50%'>
+ <tr>
+ <td><div id="mapdiv"></div></td>
+ </tr>
+ <tr>
+ <td>
+ <input type="text" id="address" name="address" value="" size="35"/>
+ <a href="#" onclick="user_submit(); return false;">Geocode</a>
+ </td>
+ </tr>
+ </table>
+ <a href='#' onclick='changetohybrid();'>change to hybrid</a>
+ <div id="position"></div>
+ </center>
+</body>
+</html>
+
View
@@ -22,7 +22,6 @@ var init = function() {
* @param {String} element The HTML element to replace with a map
* @param {String} api The API to use, one of 'google', 'googlev3', 'yahoo', 'microsoft', 'openstreetmap', 'multimap', 'map24', 'openlayers', 'mapquest'. If omitted, first loaded provider implementation is used.
* @param {Bool} debug optional parameter to turn on debug support - this uses alert panels for unsupported actions
- * @param {String} key optional api key value used for microsoft v7 map provider
* @exports Mapstraction as mxn.Mapstraction
*/
var Mapstraction = mxn.Mapstraction = function(element, api, debug) {
@@ -36,8 +35,7 @@ var Mapstraction = mxn.Mapstraction = function(element, api, debug) {
* @type {String}
*/
this.api = api;
- /**
-
+
this.maps = {};
/**
View
@@ -6,7 +6,7 @@
* @private
*/
var init = function() {
- this.invoker.go('init');
+ this.invoker.go('init');
};
/**
@@ -16,31 +16,30 @@ var init = function() {
* @param {String} api The API to use, currently only 'mapquest' is supported
* @param {Function} callback The function to call when a geocode request returns (function(waypoint))
* @param {Function} error_callback The optional function to call when a geocode request fails
- * @param {String} key Optional api auth key. Currently only used for Microsoft v7.
* @exports Geocoder as mxn.Geocoder
*/
-var Geocoder = mxn.Geocoder = function (api, callback, error_callback) {
- this.api = api;
- this.geocoders = {};
- this.callback = callback;
- this.error_callback = error_callback || function(){};
-
- // set up our invoker for calling API methods
- this.invoker = new mxn.Invoker(this, 'Geocoder', function(){ return this.api; });
- init.apply(this);
+var Geocoder = mxn.Geocoder = function (api, callback, error_callback) {
+ this.api = api;
+ this.geocoders = {};
+ this.callback = callback;
+ this.error_callback = error_callback || function(){};
+
+ // set up our invoker for calling API methods
+ this.invoker = new mxn.Invoker(this, 'Geocoder', function(){ return this.api; });
+ init.apply(this);
};
mxn.addProxyMethods(Geocoder, [
-
- /**
- * Geocodes the provided address.
- * @name mxn.Geocoder#geocode
- * @function
- * @param {Object} address Address hash (street, locality, region, country), literal address as String, or LatLanPoint object
- */
- 'geocode',
-
- 'geocode_callback'
+
+ /**
+ * Geocodes the provided address.
+ * @name mxn.Geocoder#geocode
+ * @function
+ * @param {Object} address Address hash, keys are: street, locality, region, country.
+ */
+ 'geocode',
+
+ 'geocode_callback'
]);
@@ -50,12 +49,12 @@ mxn.addProxyMethods(Geocoder, [
* @param {String} api The API to swap to
*/
Geocoder.prototype.swap = function(api) {
- if (this.api == api) { return; }
+ if (this.api == api) { return; }
- this.api = api;
- if (!this.geocoders.hasOwnProperty(this.api)) {
- init.apply(this);
- }
+ this.api = api;
+ if (!this.geocoders.hasOwnProperty(this.api)) {
+ init.apply(this);
+ }
};
})();
@@ -20,7 +20,7 @@ Mapstraction: {
'location': new mxn.LatLonPoint(ll.latitude, ll.longitude),
'position': {x:_x, y:_y}
};
- me.events.rightClick.fire(_event);
+ me.rightClick.fire(_event);
});
Microsoft.Maps.Events.addHandler(this.maps[api], 'click', function(event){
var map = me.maps[me.api];
@@ -40,35 +40,35 @@ Mapstraction: {
'position': {x:_x, y:_y}
};
if(event.isSecondary){
- me.events.rightClick.fire(_event);
+ me.rightClick.fire(_event);
}
else{
- me.events.click.fire(_event);
+ me.click.fire(_event);
}
}
});
Microsoft.Maps.Events.addHandler(this.maps[api],'viewchangeend', function(event){
- me.events.changeZoom.fire();
+ me.changeZoom.fire();
});
Microsoft.Maps.Events.addHandler(this.maps[api],'viewchangeend', function(event){
- me.events.endPan.fire();
+ me.endPan.fire();
});
Microsoft.Maps.Events.addHandler(this.maps[api],'viewchange', function(event){
- me.events.endPan.fire();
- });
- Microsoft.Maps.Events.addHandler(this.maps[api],'mousemove', function(event){
- var map = me.maps[me.api];
-
- var _x = event.getX();
- var _y = event.getY();
- var pixel = new Microsoft.Maps.Point(_x, _y);
- var ll = map.tryPixelToLocation(pixel);
- var _event = {
- 'location': new mxn.LatLonPoint(ll.latitude, ll.longitude),
- 'position': {x:_x, y:_y}
- };
- me.events.mouseMove.fire(_event);
+ me.endPan.fire();
});
+ // Microsoft.Maps.Events.addHandler(this.maps[api],'mousemove', function(event){
+ // var map = me.maps[me.api];
+
+ // var _x = event.getX();
+ // var _y = event.getY();
+ // var pixel = new Microsoft.Maps.Point(_x, _y);
+ // var ll = map.tryPixelToLocation(pixel);
+ // var _event = {
+ // 'location': new mxn.LatLonPoint(ll.latitude, ll.longitude),
+ // 'position': {x:_x, y:_y}
+ // };
+ // me.mouseMove.fire(_event);
+ // });
},
@@ -19,8 +19,8 @@ mxn.register('openlayers', {
// initialize layers map (this was previously in mxn.core.js)
this.layers = {};
- this.layers.osm = new OpenLayers.Layer.TMS(
- 'OpenStreetMap',
+ this.layers.osmmapnik = new OpenLayers.Layer.TMS(
+ 'OSM Mapnik',
[
"http://a.tile.openstreetmap.org/",
"http://b.tile.openstreetmap.org/",
@@ -49,7 +49,38 @@ mxn.register('openlayers', {
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
+ }
+ );
+
// deal with click
map.events.register('click', map, function(evt){
var lonlat = map.getLonLatFromViewPortPx(evt.xy);
@@ -83,8 +114,12 @@ mxn.register('openlayers', {
}
}
+ map.addLayer(this.layers.osmmapnik);
map.addLayer(this.layers.osm);
+<<<<<<< HEAD
this.tileLayers.push(["http://a.tile.openstreetmap.org/", this.layers.osm, true]);
+=======
+>>>>>>> parent of 4243f7a... Added OpenLayers support for addTileLayer.
this.maps[api] = map;
this.loaded[api] = true;
},
@@ -378,28 +413,31 @@ mxn.register('openlayers', {
addTileLayer: function(tile_url, opacity, copyright_text, min_zoom, max_zoom, map_type) {
var map = this.maps[this.api];
- var new_tile_url = tile_url.replace(/\{Z\}/g,'${z}');
- new_tile_url = new_tile_url.replace(/\{X\}/g,'${x}');
- new_tile_url = new_tile_url.replace(/\{Y\}/g,'${y}');
+ tile_url = tile_url.replace(/\{Z\}/g,'${z}');
+ tile_url = tile_url.replace(/\{X\}/g,'${x}');
+ tile_url = tile_url.replace(/\{Y\}/g,'${y}');
var overlay = new OpenLayers.Layer.XYZ(copyright_text,
- new_tile_url,
+ tile_url,
{sphericalMercator: false, opacity: opacity}
);
if(!map_type) {
overlay.addOptions({displayInLayerSwitcher: false, isBaseLayer: false});
}
map.addLayer(overlay);
- this.tileLayers.push( [tile_url, overlay, false] );
},
toggleTileLayer: function(tile_url) {
var map = this.maps[this.api];
+<<<<<<< HEAD
for (var f=this.tileLayers.length-1; f>=0; f--) {
if(this.tileLayers[f][0] == tile_url) {
this.tileLayers[f][2] = !this.tileLayers[f][2];
this.tileLayers[f][1].setVisibility(this.tileLayers[f][2]);
}
}
+=======
+
+>>>>>>> parent of 4243f7a... Added OpenLayers support for addTileLayer.
// TODO: Add provider code
},

0 comments on commit a82e5a7

Please sign in to comment.