-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
118 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,30 @@ | ||
mxn.register('{{api_id}}', { | ||
mxn.register('{{api_id}}', { | ||
|
||
MapstractionGeocoder: { | ||
Geocoder: { | ||
|
||
init: function(element, api) { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
dezfowler
Author
Member
|
||
var me = this; | ||
|
||
// TODO: Add provider code | ||
}, | ||
|
||
geocode: function(address){ | ||
var return_location = {}; | ||
var mapstraction_geodocer = this; | ||
var mapstraction_geocoder = this; | ||
|
||
// TODO: Add provider code | ||
}, | ||
geocode_callback: function(response, mapstraction_geocoder){ | ||
|
||
geocode_callback: function(response){ | ||
var return_location = {}; | ||
|
||
// TODO: Add provider code | ||
//return_location.street = ''; | ||
//return_location.locality = ''; | ||
//return_location.region = ''; | ||
//return_location.country = ''; | ||
//return_location.point = new mxn.LatLonPoint(...); | ||
|
||
this.callback(return_location); | ||
} | ||
} | ||
}) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,16 @@ | ||
mxn.register('cartociudad', { | ||
|
||
MapstractionGeocoder: { | ||
Geocoder: { | ||
|
||
init: function(element, api) { | ||
This comment has been minimized.
Sorry, something went wrong.
brunob
Contributor
|
||
this.geocoders[api] = new metodosCartociudad(); | ||
}, | ||
|
||
geocode: function(address){ | ||
var return_location = {}; | ||
var mapstraction_geodocer = this; | ||
|
||
address.error=0; //creamos una variable para devolver errores | ||
address.error = 0; //creamos una variable para devolver errores | ||
|
||
this.geocoders[this.api].queryNomenclator(address); | ||
|
||
|
@@ -18,13 +19,14 @@ MapstractionGeocoder: { | |
} | ||
else { | ||
this.geocoders[this.api].addressToMapstraction(address); | ||
this.callback(address, this); | ||
this.callback(address); | ||
} | ||
}, | ||
|
||
geocode_callback: function(response, mapstraction_geocoder){ | ||
var return_location = {}; | ||
|
||
// TODO: Add provider code | ||
} | ||
} | ||
}) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,86 +1,60 @@ | ||
(function(){ | ||
/** | ||
* @exports mxn.util.$m as $m | ||
*/ | ||
var $m = mxn.util.$m; | ||
|
||
/** | ||
* Initialise our provider. This function should only be called | ||
* from within mapstraction code, not exposed as part of the API. | ||
* @private | ||
*/ | ||
var init = function() { | ||
this.invoker.go('init', [ this.callback, this.api, this.error_callback ]); | ||
this.invoker.go('init', [ this.api, this.callback, this.error_callback ]); | ||
}; | ||
|
||
/** | ||
* MapstractionGeocoder instantiates a geocoder with some API choice | ||
* @param {Function} callback The function to call when a geocode request returns (function(waypoint)) | ||
* Geocoder instantiates a geocoder with some API choice | ||
* @name mxn.Geocoder | ||
* @constructor | ||
* @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 | ||
* @constructor | ||
* @exports Geocoder as mxn.Geocoder | ||
*/ | ||
var MapstractionGeocoder = mxn.MapstractionGeocoder = function (callback, api, error_callback) { | ||
this.api = api; | ||
this.callback = callback; | ||
this.geocoders = new Object(); | ||
if(error_callback == null) { | ||
this.error_callback = this.geocode_error | ||
} else { | ||
this.error_callback = error_callback; | ||
} | ||
|
||
// set up our invoker for calling API methods | ||
this.invoker = new mxn.Invoker(this, 'MapstractionGeocoder', function(){ return this.api; }); | ||
init.apply(this); | ||
} | ||
|
||
mxn.addProxyMethods(MapstractionGeocoder, [ | ||
|
||
/* | ||
* Implements the geocoding process | ||
*/ | ||
'geocode', | ||
|
||
/* | ||
* Implements the callback fucnction in geocoding process | ||
*/ | ||
'geocode_callback', | ||
|
||
]) | ||
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); | ||
}; | ||
|
||
/** | ||
* 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) { | ||
this.invoker.go('geocode',arguments); | ||
} | ||
mxn.addProxyMethods(Geocoder, [ | ||
|
||
/** | ||
* Geocodes the provided address. | ||
* @name mxn.Geocoder#geocode | ||
* @function | ||
* @param {Object} address Address hash, keys are: street, locality, region, country. | ||
*/ | ||
'geocode', | ||
|
||
'geocode_callback' | ||
|
||
/** | ||
* Default handler for geocode request completion | ||
*/ | ||
MapstractionGeocoder.prototype.geocode_callback = function(response, mapstraction_geocoder) { | ||
this.invoker.go('geocode_callback',arguments); | ||
} | ||
]); | ||
|
||
/** | ||
* Change the Routing API to use | ||
* Change the geocoding API in use | ||
* @name mxn.Geocoder#swap | ||
* @param {String} api The API to swap to | ||
*/ | ||
MapstractionGeocoder.prototype.swap = function(api) { | ||
if (this.api == api) { return; } | ||
Geocoder.prototype.swap = function(api) { | ||
if (this.api == api) { return; } | ||
|
||
this.api = api; | ||
if (this.geocoders[this.api] == undefined) { | ||
init.apply(this); | ||
} | ||
} | ||
|
||
/** | ||
* Default Geocode error function | ||
*/ | ||
MapstractionGeocoder.prototype.geocode_error = function(response) { | ||
alert("Sorry, we were unable to geocode that address"); | ||
} | ||
this.api = api; | ||
if (!this.geocoders.hasOwnProperty(this.api)) { | ||
init.apply(this); | ||
} | ||
}; | ||
|
||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,56 @@ | ||
mxn.register('google', { | ||
|
||
MapstractionGeocoder: { | ||
Geocoder: { | ||
|
||
init: function(element, api) { | ||
var me = this; | ||
me.geocoders[api] = new GClientGeocoder(); | ||
this.geocoders[api] = new GClientGeocoder(); | ||
}, | ||
geocode: function(address){ | ||
var return_location = {}; | ||
var mapstraction_geocoder = this; | ||
|
||
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); }); | ||
}, | ||
geocode_callback: function(response, mapstraction_geocoder){ | ||
var return_location = {}; | ||
geocode: function(address){ | ||
var me = this; | ||
|
||
if (!address.hasOwnProperty('address') || address.address === null || address.address === '') { | ||
address.address = [ address.street, address.locality, address.region, address.country ].join(', '); | ||
} | ||
|
||
if (!response || response.Status.code != 200) { | ||
mapstraction_geocoder.error_callback(response); | ||
} else { | ||
return_location.street = ""; | ||
return_location.locality = ""; | ||
return_location.region = ""; | ||
return_location.country = ""; | ||
this.geocoders[this.api].getLocations(address.address, function(response) { | ||
me.geocode_callback(response); | ||
}); | ||
}, | ||
|
||
geocode_callback: function(response){ | ||
var return_location = {}; | ||
|
||
if (typeof(response) === 'undefined' || !response.hasOwnProperty('Status') || response.Status.code != 200) { | ||
this.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.point = new mxn.LatLonPoint(place.Point.coordinates[1], | ||
place.Point.coordinates[0]); | ||
mapstraction_geocoder.callback(return_location); | ||
} | ||
var place = response.Placemark[0]; | ||
var working = place.AddressDetails.Country.AdministrativeArea; | ||
if(working !== null) { | ||
return_location.region = working.AdministrativeAreaName; | ||
if(working.SubAdministrativeArea !== null) { | ||
working = working.SubAdministrativeArea; | ||
if(working.Locality !== null) { | ||
working = working.Locality; | ||
return_location.locality = working.LocalityName; | ||
if(working.Thoroughfare !== null) { | ||
return_location.street = working.Thoroughfare.ThoroughfareName; | ||
} | ||
} | ||
} | ||
} | ||
|
||
return_location.country = place.AddressDetails.Country.CountryNameCode; | ||
return_location.point = new mxn.LatLonPoint(place.Point.coordinates[1], place.Point.coordinates[0]); | ||
|
||
this.callback(return_location); | ||
} | ||
} | ||
} | ||
}) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Since http://github.com/mapstraction/mxn/commit/05327e48c96f31f4e20f12b6abe144822f38f038#L3R9
Not sure but, should be replaced (?) by this