angular-osm
Advanced tools
Comparing version 0.0.1 to 0.0.2
@@ -90,3 +90,11 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
var osmAPIModule = angular.module('osm.api', [_settings2.default.name, _utils2.default.name, 'base64']).service('osmAPI', _api2.default); | ||
var osmAPIModule = angular.module('osm.api', [_settings2.default.name, _utils2.default.name, 'base64']).service('osmAPI', _api2.default).provider('osmAPI', function osmAPIProvider() { | ||
this.options = { | ||
url: 'http://api.openstreetmap.org/api' | ||
}; | ||
this.$get = function osmAPIFactory($base64, $http, $q, osmSettingsService, osmUtilsService) { | ||
return new _api2.default($base64, $http, $q, osmSettingsService, osmUtilsService, this.options); | ||
}; | ||
this.$get.$inject = ['$base64', '$http', '$q', 'osmSettingsService', 'osmUtilsService']; | ||
}); | ||
@@ -116,2 +124,4 @@ exports.default = osmAPIModule; | ||
* @name osm.oauth.osmAuthService | ||
* @description The main idea is use geojson object where it is possible | ||
* for the rest of the API (changeset, ...) it's XML2JS that is used so always expect objects. | ||
* @param {any} $base64 | ||
@@ -122,4 +132,7 @@ * @param {any} $http | ||
*/ | ||
osmAPI.$inject = ['$base64', '$http', '$q', 'osmSettingsService', 'osmUtilsService']; | ||
function osmAPI($base64, $http, $q, osmSettingsService, osmUtilsService) { | ||
function osmAPI($base64, $http, $q, osmSettingsService, osmUtilsService, options) { | ||
this.url = options.url; | ||
// ------------------ CREDENTIALS ----------------- | ||
/** | ||
@@ -136,8 +149,6 @@ * @ngdoc method | ||
this.getUserDetails().then(function (data) { | ||
var parsed = osmUtilsService.parseXml(data); | ||
var users = parsed.getElementsByTagName('user'); | ||
if (users.length === 1) { | ||
osmSettingsService.setUserID(users[0].id); | ||
if (data.osm.user) { | ||
osmSettingsService.setUserID(data.osm.user._id); | ||
} | ||
deferred.resolve(users.length > 0); | ||
deferred.resolve(data.osm.user !== undefined); | ||
}, function (error) { | ||
@@ -193,4 +204,102 @@ deferred.reject(error); | ||
}; | ||
/** | ||
* @ngdoc method | ||
* @name setOauth | ||
* @description use oauth object to call API | ||
* @methodOf osm.api.osmAPI | ||
*/ | ||
this.setOauth = function setOauth(oauth) { | ||
this._oauth = oauth; | ||
}; | ||
/** | ||
* @ngdoc method | ||
* @name setOauth | ||
* @description use oauth object to call API | ||
* @methodOf osm.api.osmAPI | ||
* @return {Object} oauth | ||
*/ | ||
this.getOauth = function getOauth() { | ||
return this._oauth; | ||
}; | ||
// ------------------ INTERNAL CALL SERVER (API) ----------------- | ||
function isElement(obj) { | ||
try { | ||
//Using W3 DOM2 (works for FF, Opera and Chrom) | ||
return obj instanceof HTMLElement; | ||
} catch (e) { | ||
//Browsers not supporting W3 DOM2 don't have HTMLElement and | ||
//an exception is thrown and we end up here. Testing some | ||
//properties that all elements have. (works on IE7) | ||
return (typeof obj === 'undefined' ? 'undefined' : _typeof(obj)) === "object" && obj.nodeType === 1 && _typeof(obj.style) === "object" && _typeof(obj.ownerDocument) === "object"; | ||
} | ||
} | ||
/** | ||
* @ngdoc method | ||
* @name xhr | ||
* @description call the API | ||
* @param {Object} options | ||
* @comment | ||
* ``` | ||
var options = { | ||
method: 'GET', // POST, DELETE, PUT | ||
path: '/0.6/changesets', //without the /api | ||
data: content //if you need a payload | ||
}; | ||
osmAPI.xhr(options); | ||
``` | ||
* @methodOf osm.api.osmAPI | ||
* @return {Object} oauth | ||
*/ | ||
this.xhr = function (options) { | ||
var deferred = $q.defer(); | ||
var promise = void 0; | ||
var hasOauth = this._oauth; | ||
if (hasOauth) { | ||
options.path = '/api' + options.path; | ||
if (options.data) { | ||
options.body = options.data; | ||
options.data = undefined; | ||
} | ||
promise = this._oauth.xhr(options); | ||
} else { | ||
options.url = this.url + options.path; | ||
options.headers = { | ||
Authorization: this.getAuthorization() | ||
}; | ||
promise = $http(options); | ||
} | ||
promise.then(function (data) { | ||
var d; | ||
var t = function t(d) { | ||
if (!d) { | ||
return d; | ||
} | ||
if (d.substr) { | ||
if (d.substr(0, 5) === '<?xml') { | ||
return osmUtilsService.xml2js(d); | ||
} | ||
} else if (isElement(d)) { | ||
return osmUtilsService.x2js.dom2js(d); | ||
} | ||
return d; | ||
}; | ||
if (hasOauth) { | ||
d = data; | ||
} else { | ||
d = data.data; | ||
} | ||
deferred.resolve(t(d)); | ||
}, function (error) { | ||
deferred.reject(error); | ||
}); | ||
return deferred.promise; | ||
}; | ||
/** | ||
* @ngdoc method | ||
* @name getAuthenticated | ||
@@ -203,7 +312,9 @@ * @description send a get request to OSM with | ||
this.getAuthenticated = function (method, config) { | ||
if (config === undefined) { | ||
config = {}; | ||
var _config = angular.copy(config); | ||
if (!_config) { | ||
_config = {}; | ||
} | ||
config.headers = { Authorization: this.getAuthorization() }; | ||
return this.get(method, config); | ||
_config.method = 'GET'; | ||
_config.path = method; | ||
return this.xhr(_config); | ||
}; | ||
@@ -222,7 +333,7 @@ /** | ||
var self = this; | ||
var url = osmSettingsService.getOSMAPI() + method; | ||
var url = this.url + method; | ||
$http.get(url, config).then(function (data) { | ||
deferred.resolve(data.data); | ||
}, function (data) { | ||
deferred.reject(data); | ||
deferred.resolve(osmUtilsService.xml2js(data.data)); | ||
}, function (error) { | ||
deferred.reject(error); | ||
}); | ||
@@ -242,16 +353,10 @@ return deferred.promise; | ||
this.put = function (method, content, config) { | ||
var deferred = $q.defer(); | ||
var self = this; | ||
if (config === undefined) { | ||
if (!config) { | ||
config = {}; | ||
} | ||
config.headers = { Authorization: this.getAuthorization() }; | ||
var url = osmSettingsService.getOSMAPI() + method; | ||
$http.put(url, content, config).then(function (data) { | ||
deferred.resolve(data.data); | ||
}, function (data) { | ||
deferred.reject(data); | ||
}); | ||
return deferred.promise; | ||
var _config = angular.copy(config); | ||
_config.method = 'PUT'; | ||
_config.path = method; | ||
_config.data = osmUtilsService.js2xml(content); | ||
return this.xhr(_config); | ||
}; | ||
@@ -268,18 +373,13 @@ /** | ||
this.delete = function (method, config) { | ||
var deferred = $q.defer(); | ||
var self = this; | ||
if (config === undefined) { | ||
if (!config) { | ||
config = {}; | ||
} | ||
config.headers = { Authorization: this.getAuthorization() }; | ||
config.url = osmSettingsService.getOSMAPI() + method; | ||
config.method = 'delete'; | ||
$http(config).then(function (data) { | ||
deferred.resolve(data.data); | ||
}, function (data) { | ||
deferred.reject(data); | ||
}); | ||
return deferred.promise; | ||
var _config = angular.copy(config); | ||
_config.method = 'DELETE'; | ||
_config.path = method; | ||
return this.xhr(_config); | ||
}; | ||
// ------------------ CHANGESET ----------------- | ||
/** | ||
@@ -294,4 +394,7 @@ * @ngdoc method | ||
var deferred = $q.defer(); | ||
var changeset = '<osm><changeset><tag k="created_by" v="Angular-OSM"/><tag k="comment" v="'; | ||
changeset += comment + '"/></changeset></osm>'; | ||
var changeset = { osm: { | ||
changeset: { | ||
tag: [{ _k: 'created_by', _v: 'Angular-OSM' }, { _k: 'comment', _v: comment }] | ||
} | ||
} }; | ||
this.put('/0.6/changeset/create', changeset).then(function (data) { | ||
@@ -316,7 +419,9 @@ osmSettingsService.setChangeset(data); | ||
this.get('/0.6/changesets', config).then(function (data) { | ||
var parsed = osmUtilsService.parseXml(data); | ||
var changesets = parsed.getElementsByTagName('changeset'); | ||
var changesets = data.osm.changeset; | ||
if (changesets.length > 0) { | ||
osmSettingsService.setChangeset(changesets[0].id); | ||
deferred.resolve(changesets[0].id); | ||
} else if (changesets._id) { | ||
osmSettingsService.setChangeset(changesets._id); | ||
deferred.resolve(changesets._id); | ||
} else { | ||
@@ -343,4 +448,19 @@ osmSettingsService.setChangeset(); | ||
}; | ||
// ------------------ USER API ----------------- | ||
/** | ||
* @ngdoc method | ||
* @name getUserById | ||
* @methodOf osm.api.osmAPI | ||
* @param {string} id of the user | ||
* @returns {Promise} $http.get response | ||
* /0.6/user/#id | ||
*/ | ||
this.getUserById = function (id) { | ||
return this.getAuthenticated('/0.6/user/' + id); | ||
}; | ||
/** | ||
* @ngdoc method | ||
* @name getUserDetails | ||
@@ -356,2 +476,28 @@ * @methodOf osm.api.osmAPI | ||
* @ngdoc method | ||
* @name getUserPreferences | ||
* @methodOf osm.api.osmAPI | ||
* @returns {Promise} $http.get response | ||
* /0.6/user/preferences | ||
*/ | ||
this.getUserPreferences = function () { | ||
return this.getAuthenticated('/0.6/user/preferences'); | ||
}; | ||
/** | ||
* @ngdoc method | ||
* @name putUserPreferences | ||
* @methodOf osm.api.osmAPI | ||
* @param {string} key the preference key | ||
* @param {string} value the preference value | ||
* @returns {Promise} $http.get response | ||
* /0.6/user/preferences | ||
*/ | ||
this.putUserPreferences = function (key, value) { | ||
return this.put('/0.6/user/preferences/' + key, value); | ||
}; | ||
//------------------ MAP DATA ------------------------- | ||
/** | ||
* @ngdoc method | ||
* @name getMap | ||
@@ -374,2 +520,21 @@ * @methodOf osm.api.osmAPI | ||
* @ngdoc method | ||
* @name getMapGeoJSON | ||
* @methodOf osm.api.osmAPI | ||
* @param {string} bbox the bounding box | ||
* @returns {Promise} $http.get response | ||
*/ | ||
this.getMapGeoJSON = function (bbox) { | ||
var self = this; | ||
var deferred = $q.defer(); | ||
self.getMap(bbox).then(function (nodes) { | ||
var geojsonNodes = osmUtilsService.js2geojson(nodes); | ||
deferred.resolve(geojsonNodes); | ||
}, function (error) { | ||
deferred.reject(error); | ||
}); | ||
return deferred.promise; | ||
}; | ||
/** | ||
* @ngdoc method | ||
* @name getNotes | ||
@@ -383,114 +548,148 @@ * @methodOf osm.api.osmAPI | ||
top is the latitude of the top (northernmost) side of the bounding box. | ||
* @param {string} format Currently the format rss, xml, json and gpx are supported. | ||
* @returns {Promise} $http.get response | ||
* /0.6/notes[.format]?bbox=bbox | ||
*/ | ||
this.getNotes = function (bbox, format) { | ||
var url = '/0.6/notes'; | ||
if (format) { | ||
url += '.' + format; | ||
} | ||
url += '?bbox=' + bbox; | ||
this.getNotes = function (bbox) { | ||
var url = '/0.6/notes?bbox=' + bbox; | ||
return this.get(url); | ||
}; | ||
//------------------ ELEMENTS: Node ---------------- | ||
/** | ||
* @ngdoc method | ||
* @name updateNode | ||
* @name createNode | ||
* @methodOf osm.api.osmAPI | ||
* @param {Object} currentNode geojson | ||
* @param {Object} updatedNode geojson | ||
* @param {Object/string} node | ||
var node = {osm: {node: { | ||
_changeset: '12', _lat: '...', _lon: '...', | ||
tags: [ | ||
{_k: '...', _v: '...'} | ||
] | ||
}}}; | ||
* @returns {Promise} $http.put response | ||
* PUT /0.6/node/create | ||
*/ | ||
this.createNode = function (node) { | ||
return this.put('/0.6/node/create', node); | ||
}; | ||
/** | ||
* @ngdoc method | ||
* @name getNode | ||
* @methodOf osm.api.osmAPI | ||
* @param {string} id | ||
* @returns {Promise} $http.get response | ||
* /0.6/map?bbox=bbox | ||
* GET /0.6/node/#id | ||
*/ | ||
this.updateNode = function (currentNode, updatedNode) { | ||
//we need to do the diff and build the xml | ||
//first try to find the node by id | ||
var nodes = osmSettingsService.getNodes(); | ||
var node = nodes.getElementById(currentNode.properties.id); | ||
var deferred = $q.defer(); //only for errors | ||
if (node === null) { | ||
deferred.reject({ | ||
msg: 'can t find node', | ||
currentNode: currentNode, | ||
updatedNode: updatedNode, | ||
osmNode: node | ||
}); | ||
return deferred.promise; | ||
} | ||
var tag; | ||
node.setAttribute('changeset', osmSettingsService.getChangeset()); | ||
node.setAttribute('user', osmSettingsService.getUserName()); | ||
while (node.getElementsByTagName('tag')[0]) { | ||
node.removeChild(node.getElementsByTagName('tag')[0]); | ||
} | ||
var osm = document.createElement('osm'); | ||
var value; | ||
osm.appendChild(node); | ||
for (var property in updatedNode.properties.tags) { | ||
if (updatedNode.properties.tags.hasOwnProperty(property)) { | ||
value = updatedNode.properties.tags[property]; | ||
if (value === undefined) { | ||
continue; | ||
} | ||
tag = document.createElement('tag'); | ||
tag.setAttribute('k', property); | ||
tag.setAttribute('v', value); | ||
node.appendChild(tag); | ||
} | ||
} | ||
var nodeType; | ||
if (updatedNode.geometry.type === 'Polygon') { | ||
nodeType = 'way'; | ||
} else if (updatedNode.geometry.type === 'Point') { | ||
nodeType = 'node'; | ||
} else if (updatedNode.geometry.type === 'LineString') { | ||
nodeType = 'way'; | ||
} else { | ||
deferred.reject({ | ||
msg: 'geojson type not supported', | ||
currentNode: currentNode, | ||
updatedNode: updatedNode, | ||
osmNode: node | ||
}); | ||
return deferred.promise; | ||
} | ||
//put request !! | ||
var url = '/0.6/' + nodeType + '/' + currentNode.properties.id; | ||
return this.put(url, osm.outerHTML); | ||
this.getNode = function (id) { | ||
return this.get('/0.6/node/' + id); | ||
}; | ||
/** | ||
* @ngdoc method | ||
* @name createNode | ||
* @name deleteNode | ||
* @methodOf osm.api.osmAPI | ||
* @param {Object/string} node as xml or geojson | ||
* @param {string} id | ||
* @returns {Promise} $http.delete response | ||
* DELETE /0.6/node/#id | ||
*/ | ||
this.deleteNode = function (id) { | ||
return this.delete('/0.6/node/' + id); | ||
}; | ||
//------------------ ELEMENTS: WAY ---------------- | ||
/** | ||
* @ngdoc method | ||
* @name createWay | ||
* @methodOf osm.api.osmAPI | ||
* @param {Object/string} way | ||
var way = {osm: {way: { | ||
_changeset: '12', _lat: '...', _lon: '...', | ||
tags: [ | ||
{_k: '...', _v: '...'} | ||
], | ||
nd: [ | ||
{_ref: '123'}, | ||
{_ref: '456'}, | ||
] | ||
}}}; | ||
* @returns {Promise} $http.put response | ||
* /0.6/node/create | ||
* PUT /0.6/way/create | ||
*/ | ||
this.createNode = function (node) { | ||
var xmlnode = node; | ||
if ((typeof node === 'undefined' ? 'undefined' : _typeof(node)) === 'object') { | ||
xmlnode = osmUtilsService.createNodeXML(node); | ||
} | ||
return this.put('/0.6/node/create', xmlnode); | ||
this.createWay = function (way) { | ||
return this.put('/0.6/way/create', way); | ||
}; | ||
/** | ||
* @ngdoc method | ||
* @name getMapGeoJSON | ||
* @name getWay | ||
* @methodOf osm.api.osmAPI | ||
* @param {string} bbox the bounding box | ||
* @param {string} id | ||
* @returns {Promise} $http.get response | ||
* GET /0.6/way/#id | ||
*/ | ||
this.getMapGeoJSON = function (bbox) { | ||
var self = this; | ||
var deferred = $q.defer(); | ||
self.getMap(bbox).then(function (strNodes) { | ||
var xmlNodes = osmUtilsService.parseXml(strNodes); | ||
var geojsonNodes = osmUtilsService.getNodesInJSON(xmlNodes); | ||
deferred.resolve(geojsonNodes); | ||
}, function (error) { | ||
deferred.reject(error); | ||
}); | ||
return deferred.promise; | ||
this.getWay = function (id) { | ||
return this.get('/0.6/way/' + id); | ||
}; | ||
/** | ||
* @ngdoc method | ||
* @name deleteWay | ||
* @methodOf osm.api.osmAPI | ||
* @param {string} id | ||
* @returns {Promise} $http.delete response | ||
* DELETE /0.6/way/#id | ||
*/ | ||
this.deleteWay = function (id) { | ||
return this.delete('/0.6/way/' + id); | ||
}; | ||
//------------------ ELEMENTS: RELATION ---------------- | ||
/** | ||
* @ngdoc method | ||
* @name createRelation | ||
* @methodOf osm.api.osmAPI | ||
* @param {Object/string} relation | ||
var relation = {osm: {relation: { | ||
_changeset: '12', _lat: '...', _lon: '...', | ||
tags: [ | ||
{_k: '...', _v: '...'} | ||
], | ||
member: [ | ||
{_type: 'node', _role: 'stop', 'ref': '123'}, | ||
{_type: 'way', 'ref': '234'} | ||
] | ||
}}}; | ||
* @returns {Promise} $http.put response | ||
* PUT /0.6/relation/create | ||
*/ | ||
this.createRelation = function (relation) { | ||
return this.put('/0.6/relation/create', relation); | ||
}; | ||
/** | ||
* @ngdoc method | ||
* @name getRelation | ||
* @methodOf osm.api.osmAPI | ||
* @param {string} id | ||
* @returns {Promise} $http.get response | ||
* GET /0.6/relation/#id | ||
*/ | ||
this.getRelation = function (id) { | ||
return this.get('/0.6/relation/' + id); | ||
}; | ||
/** | ||
* @ngdoc method | ||
* @name deleteRelation | ||
* @methodOf osm.api.osmAPI | ||
* @param {string} id | ||
* @returns {Promise} $http.delete response | ||
* DELETE /0.6/relation/#id | ||
*/ | ||
this.deleteRelation = function (id) { | ||
return this.delete('/0.6/relation/' + id); | ||
}; | ||
} | ||
@@ -522,3 +721,3 @@ | ||
var osmSettingsModule = angular.module('osm.settings', [ngStorageModuleName]).factory('osmSettingsService', _settings2.default); | ||
var osmSettingsModule = angular.module('osm.settings', [ngStorageModuleName]).service('osmSettingsService', _settings2.default); | ||
@@ -537,3 +736,2 @@ exports.default = osmSettingsModule; | ||
/** | ||
@@ -547,70 +745,39 @@ * @ngdoc service | ||
function osmSettingsService($localStorage) { | ||
return { | ||
localStorage: $localStorage.$default({ | ||
userName: '', | ||
userID: '', | ||
credentials: '', | ||
nodes: [], | ||
changeset: '', | ||
osmAPI: '', | ||
overpassAPI: '' | ||
}), | ||
getUserName: function getUserName() { | ||
return this.localStorage.userName; | ||
}, | ||
setUserName: function setUserName(username) { | ||
this.localStorage.userName = username; | ||
}, | ||
getUserID: function getUserID() { | ||
return this.localStorage.userID; | ||
}, | ||
setUserID: function setUserID(userid) { | ||
this.localStorage.userID = userid; | ||
}, | ||
getCredentials: function getCredentials() { | ||
return this.localStorage.credentials; | ||
}, | ||
setCredentials: function setCredentials(credentials) { | ||
this.localStorage.credentials = credentials; | ||
}, | ||
getOSMAPI: function getOSMAPI() { | ||
if (this.localStorage.osmAPI) { | ||
return this.localStorage.osmAPI; | ||
} else { | ||
return 'http://api.openstreetmap.org/api'; | ||
} | ||
}, | ||
setOSMAPI: function setOSMAPI(osmAPI) { | ||
this.localStorage.osmAPI = osmAPI; | ||
}, | ||
getOverpassAPI: function getOverpassAPI() { | ||
if (this.localStorage.overpassAPI) { | ||
return this.localStorage.overpassAPI; | ||
} else { | ||
//return 'http://api.openstreetmap.org/api'; | ||
return 'http://overpass-api.de/api/interpreter'; | ||
} | ||
}, | ||
setOverpassAPI: function setOverpassAPI(overpassAPI) { | ||
this.localStorage.overpassAPI = overpassAPI; | ||
}, | ||
getNodes: function getNodes() { | ||
return this.localStorage.nodes; | ||
}, | ||
setNodes: function setNodes(nodes) { | ||
this.localStorage.nodes = nodes; | ||
}, | ||
getChangeset: function getChangeset() { | ||
return this.localStorage.changeset; | ||
}, | ||
setChangeset: function setChangeset(changeset) { | ||
this.localStorage.changeset = changeset; | ||
}, | ||
getOsmAuth: function getOsmAuth() { | ||
return this.localStorage.osmAuth; | ||
}, | ||
setOsmAuth: function setOsmAuth(options) { | ||
return this.localStorage.osmAuth = options; | ||
} | ||
this.localStorage = $localStorage.$default({ | ||
userName: '', | ||
userID: '', | ||
credentials: '', | ||
changeset: '' | ||
}); | ||
this.getUserName = function () { | ||
return this.localStorage.userName; | ||
}; | ||
this.setUserName = function (username) { | ||
this.localStorage.userName = username; | ||
}; | ||
this.getUserID = function () { | ||
return this.localStorage.userID; | ||
}; | ||
this.setUserID = function (userid) { | ||
this.localStorage.userID = userid; | ||
}; | ||
this.getCredentials = function () { | ||
return this.localStorage.credentials; | ||
}; | ||
this.setCredentials = function (credentials) { | ||
this.localStorage.credentials = credentials; | ||
}; | ||
this.getChangeset = function () { | ||
return this.localStorage.changeset; | ||
}; | ||
this.setChangeset = function (changeset) { | ||
this.localStorage.changeset = changeset; | ||
}; | ||
this.getOsmAuth = function () { | ||
return this.localStorage.osmAuth; | ||
}; | ||
this.setOsmAuth = function (options) { | ||
this.localStorage.osmAuth = options; | ||
}; | ||
} | ||
@@ -644,5 +811,9 @@ | ||
var _x2js = __webpack_require__(9); | ||
var _x2js2 = _interopRequireDefault(_x2js); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var osmUtilsModule = angular.module('osm.utils', [_settings2.default.name]).service('osmUtilsService', _utils2.default); | ||
var osmUtilsModule = angular.module('osm.utils', [_settings2.default.name, _x2js2.default.name]).service('osmUtilsService', _utils2.default); | ||
@@ -664,116 +835,13 @@ exports.default = osmUtilsModule; | ||
*/ | ||
function osmUtilsService(osmSettingsService) { | ||
var _this = this; | ||
function osmUtilsService($http, osmSettingsService, osmx2js) { | ||
this.serializer = new XMLSerializer(); | ||
if (typeof window.DOMParser !== 'undefined') { | ||
(function () { | ||
var parser = new window.DOMParser(); | ||
_this.parseXml = function parseXml(xmlStr) { | ||
return parser.parseFromString(xmlStr, 'application/xml'); | ||
}; | ||
})(); | ||
} else if (typeof window.ActiveXObject !== 'undefined') { | ||
this.parseXml = function parseXml(xmlStr) { | ||
var xmlDoc = new window.ActiveXObject('Microsoft.XMLDOM'); | ||
xmlDoc.async = 'false'; | ||
xmlDoc.loadXML(xmlStr); | ||
return xmlDoc; | ||
}; | ||
} else { | ||
throw new Error('No XML parser found'); | ||
} | ||
/** | ||
* @ngdoc method | ||
* @name createNodeXML | ||
* @name relationToGeoJSON | ||
* @methodOf osm.utils.osmUtilsService | ||
* @param {Object} node geojson | ||
* @return {string} XML | ||
* <osm> | ||
<node changeset="12" lat="..." lon="..."> | ||
<tag k="note" v="Just a node"/> | ||
... | ||
</node> | ||
</osm> | ||
*/ | ||
this.createNodeXML = function (node) { | ||
var newNode = '<osm><node changeset="CHANGESET" lat="LAT" lon="LNG">TAGS</node></osm>'; | ||
var tagTPL = '<tag k="KEY" v="VALUE"/>'; | ||
var tags = ''; | ||
var value; | ||
newNode = newNode.replace('CHANGESET', osmSettingsService.getChangeset()); | ||
for (var property in node.tags) { | ||
if (node.tags.hasOwnProperty(property)) { | ||
value = node.tags[property]; | ||
if (value === undefined || value === null) { | ||
continue; | ||
} else { | ||
tags += tagTPL.replace('KEY', property).replace('VALUE', node.tags[property]); | ||
} | ||
} | ||
} | ||
newNode = newNode.replace('TAGS', tags); | ||
newNode = newNode.replace('LNG', node.lng); | ||
newNode = newNode.replace('LAT', node.lat); | ||
return newNode; | ||
}; | ||
/** | ||
* @ngdoc method | ||
* @name serialiseXmlToString | ||
* @methodOf osm.utils.osmUtilsService | ||
* @param {Object} xml document object | ||
* @return {string} XML | ||
*/ | ||
this.serialiseXmlToString = function (xml) { | ||
return this.serializer.serializeToString(xml); | ||
}; | ||
/** | ||
* @ngdoc method | ||
* @name getTagsFromChildren | ||
* @methodOf osm.utils.osmUtilsService | ||
* @param {Object} element document element object | ||
* @return {Object} tags {k1:v1,k2: v2} | ||
*/ | ||
this.getTagsFromChildren = function (element) { | ||
var children, tags; | ||
tags = {}; | ||
for (var i = 0; i < element.children.length; i++) { | ||
children = element.children[i]; | ||
if (children.tagName !== 'tag') { | ||
continue; | ||
} | ||
tags[children.getAttribute('k')] = children.getAttribute('v'); | ||
} | ||
return tags; | ||
}; | ||
/** | ||
* @ngdoc method | ||
* @name getNameFromTags | ||
* @methodOf osm.utils.osmUtilsService | ||
* @param {Object} element document element object | ||
* @return {string} name value | ||
*/ | ||
this.getNameFromTags = function (element) { | ||
var children; | ||
for (var i = 0; i < element.children.length; i++) { | ||
children = element.children[i]; | ||
if (children.tagName !== 'tag') { | ||
continue; | ||
} | ||
if (children.getAttribute('k') === 'name') { | ||
return children.getAttribute('v'); | ||
} | ||
} | ||
}; | ||
/** | ||
* @ngdoc method | ||
* @name relationXmlToGeoJSON | ||
* @methodOf osm.utils.osmUtilsService | ||
* @param {Number} relationId id of the relation | ||
* @param {Object} relationXML document element object | ||
* @param {Object} relation json object | ||
* @return {Object} geojson | ||
*/ | ||
this.relationXmlToGeoJSON = function (relationID, relationXML) { | ||
this.relationToGeoJSON = function (relationID, relation) { | ||
var self = this; | ||
@@ -1037,17 +1105,9 @@ var features = []; | ||
}; | ||
/** | ||
* @ngdoc method | ||
* @name getNodesInJSON | ||
* @methodOf osm.utils.osmUtilsService | ||
* @param {Object} relationGeoJSON geojson | ||
* @return {Object} relation as geojson sorted | ||
*/ | ||
this.getNodesInJSON = function (xmlNodes, flatProperties) { | ||
osmSettingsService.setNodes(xmlNodes); | ||
var options = {}; | ||
if (flatProperties !== undefined) { | ||
options.flatProperties = flatProperties; | ||
} | ||
return osmtogeojson(xmlNodes, options); | ||
this.x2js = osmx2js; | ||
this.xml2js = function (xml_str) { | ||
return osmx2js.xml2js(xml_str); | ||
}; | ||
this.js2xml = function (json) { | ||
return osmx2js.js2xml(json); | ||
}; | ||
/** | ||
@@ -1101,2 +1161,21 @@ * @ngdoc method | ||
/***/ }, | ||
/* 9 */ | ||
/***/ function(module, exports) { | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
//https://github.com/abdmob/x2js as angular service | ||
var osmx2jsModule = angular.module('osm.x2js', []).provider('osmx2js', function osmx2jsProvider() { | ||
this.options = {}; | ||
this.$get = function osmx2jsFactory() { | ||
return new X2JS(this.options); //X2JS must be global | ||
}; | ||
}); | ||
exports.default = osmx2jsModule; | ||
/***/ } | ||
@@ -1103,0 +1182,0 @@ /******/ ]) |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("angular-base64"),require("ngstorage")):"function"==typeof define&&define.amd?define(["angular-base64","ngstorage"],t):"object"==typeof exports?exports.name=t(require("angular-base64"),require("ngstorage")):(e["angular-osm"]=e["angular-osm"]||{},e["angular-osm"].name=t(e["angular-base64"],e.ngstorage))}(this,function(e,t){return function(e){function t(n){if(r[n])return r[n].exports;var o=r[n]={exports:{},id:n,loaded:!1};return e[n].call(o.exports,o,o.exports,t),o.loaded=!0,o.exports}var r={};return t.m=e,t.c=r,t.p="",t(0)}([function(e,t,r){e.exports=r(1)},function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{"default":e}}Object.defineProperty(t,"__esModule",{value:!0});var o=r(2),s=(n(o),r(3)),i=n(s),a=r(4),u=n(a),l=r(7),g=n(l),c=angular.module("osm.api",[u["default"].name,g["default"].name,"base64"]).service("osmAPI",i["default"]);t["default"]=c},function(t,r){t.exports=e},function(e,t){"use strict";function r(e,t,r,o,s){this.validateCredentials=function(){var e=r.defer();return this.getUserDetails().then(function(t){var r=s.parseXml(t),n=r.getElementsByTagName("user");1===n.length&&o.setUserID(n[0].id),e.resolve(n.length>0)},function(t){e.reject(t)}),e.promise},this.setCredentials=function(t,r){o.setUserName(t);var n=e.encode(t+":"+r);return o.setCredentials(n),n},this.getCredentials=function(){return o.getCredentials()},this.getAuthorization=function(){return"Basic "+o.getCredentials()},this.clearCredentials=function(){o.setCredentials("")},this.getAuthenticated=function(e,t){return void 0===t&&(t={}),t.headers={Authorization:this.getAuthorization()},this.get(e,t)},this.get=function(e,n){var s=r.defer(),i=o.getOSMAPI()+e;return t.get(i,n).then(function(e){s.resolve(e.data)},function(e){s.reject(e)}),s.promise},this.put=function(e,n,s){var i=r.defer();void 0===s&&(s={}),s.headers={Authorization:this.getAuthorization()};var a=o.getOSMAPI()+e;return t.put(a,n,s).then(function(e){i.resolve(e.data)},function(e){i.reject(e)}),i.promise},this["delete"]=function(e,n){var s=r.defer();return void 0===n&&(n={}),n.headers={Authorization:this.getAuthorization()},n.url=o.getOSMAPI()+e,n.method="delete",t(n).then(function(e){s.resolve(e.data)},function(e){s.reject(e)}),s.promise},this.createChangeset=function(e){var t=r.defer(),n='<osm><changeset><tag k="created_by" v="Angular-OSM"/><tag k="comment" v="';return n+=e+'"/></changeset></osm>',this.put("/0.6/changeset/create",n).then(function(e){o.setChangeset(e),t.resolve(e)}),t.promise},this.getLastOpenedChangesetId=function(){var e=r.defer(),t={params:{user:o.getUserID(),open:!0}};return this.get("/0.6/changesets",t).then(function(t){var r=s.parseXml(t),n=r.getElementsByTagName("changeset");n.length>0?(o.setChangeset(n[0].id),e.resolve(n[0].id)):(o.setChangeset(),e.resolve())}),e.promise},this.closeChangeset=function(){var e=o.getChangeset();return this.put("/0.6/changeset/"+e+"/close").then(function(e){return o.setChangeset(),e})},this.getUserDetails=function(){return this.getAuthenticated("/0.6/user/details")},this.getMap=function(e){return this.get("/0.6/map?bbox="+e)},this.getNotes=function(e,t){var r="/0.6/notes";return t&&(r+="."+t),r+="?bbox="+e,this.get(r)},this.updateNode=function(e,t){var n=o.getNodes(),s=n.getElementById(e.properties.id),i=r.defer();if(null===s)return i.reject({msg:"can t find node",currentNode:e,updatedNode:t,osmNode:s}),i.promise;var a;for(s.setAttribute("changeset",o.getChangeset()),s.setAttribute("user",o.getUserName());s.getElementsByTagName("tag")[0];)s.removeChild(s.getElementsByTagName("tag")[0]);var u,l=document.createElement("osm");l.appendChild(s);for(var g in t.properties.tags)if(t.properties.tags.hasOwnProperty(g)){if(u=t.properties.tags[g],void 0===u)continue;a=document.createElement("tag"),a.setAttribute("k",g),a.setAttribute("v",u),s.appendChild(a)}var c;if("Polygon"===t.geometry.type)c="way";else if("Point"===t.geometry.type)c="node";else{if("LineString"!==t.geometry.type)return i.reject({msg:"geojson type not supported",currentNode:e,updatedNode:t,osmNode:s}),i.promise;c="way"}var f="/0.6/"+c+"/"+e.properties.id;return this.put(f,l.outerHTML)},this.createNode=function(e){var t=e;return"object"===("undefined"==typeof e?"undefined":n(e))&&(t=s.createNodeXML(e)),this.put("/0.6/node/create",t)},this.getMapGeoJSON=function(e){var t=this,n=r.defer();return t.getMap(e).then(function(e){var t=s.parseXml(e),r=s.getNodesInJSON(t);n.resolve(r)},function(e){n.reject(e)}),n.promise}}Object.defineProperty(t,"__esModule",{value:!0});var n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol?"symbol":typeof e};r.$inject=["$base64","$http","$q","osmSettingsService","osmUtilsService"],t["default"]=r},function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{"default":e}}Object.defineProperty(t,"__esModule",{value:!0});var o=r(5),s=n(o),i=r(6),a=n(i),u=a["default"]?a["default"].name:"ngStorage",l=angular.module("osm.settings",[u]).factory("osmSettingsService",s["default"]);t["default"]=l},function(e,t){"use strict";function r(e){return{localStorage:e.$default({userName:"",userID:"",credentials:"",nodes:[],changeset:"",osmAPI:"",overpassAPI:""}),getUserName:function(){return this.localStorage.userName},setUserName:function(e){this.localStorage.userName=e},getUserID:function(){return this.localStorage.userID},setUserID:function(e){this.localStorage.userID=e},getCredentials:function(){return this.localStorage.credentials},setCredentials:function(e){this.localStorage.credentials=e},getOSMAPI:function(){return this.localStorage.osmAPI?this.localStorage.osmAPI:"http://api.openstreetmap.org/api"},setOSMAPI:function(e){this.localStorage.osmAPI=e},getOverpassAPI:function(){return this.localStorage.overpassAPI?this.localStorage.overpassAPI:"http://overpass-api.de/api/interpreter"},setOverpassAPI:function(e){this.localStorage.overpassAPI=e},getNodes:function(){return this.localStorage.nodes},setNodes:function(e){this.localStorage.nodes=e},getChangeset:function(){return this.localStorage.changeset},setChangeset:function(e){this.localStorage.changeset=e},getOsmAuth:function(){return this.localStorage.osmAuth},setOsmAuth:function(e){return this.localStorage.osmAuth=e}}}Object.defineProperty(t,"__esModule",{value:!0}),r.$inject=["$localStorage"],t["default"]=r},function(e,r){e.exports=t},function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{"default":e}}Object.defineProperty(t,"__esModule",{value:!0});var o=r(8),s=n(o),i=r(4),a=n(i),u=angular.module("osm.utils",[a["default"].name]).service("osmUtilsService",s["default"]);t["default"]=u},function(e,t){"use strict";function r(e){var t=this;if(this.serializer=new XMLSerializer,"undefined"!=typeof window.DOMParser)!function(){var e=new window.DOMParser;t.parseXml=function(t){return e.parseFromString(t,"application/xml")}}();else{if("undefined"==typeof window.ActiveXObject)throw new Error("No XML parser found");this.parseXml=function(e){var t=new window.ActiveXObject("Microsoft.XMLDOM");return t.async="false",t.loadXML(e),t}}this.createNodeXML=function(t){var r,n='<osm><node changeset="CHANGESET" lat="LAT" lon="LNG">TAGS</node></osm>',o='<tag k="KEY" v="VALUE"/>',s="";n=n.replace("CHANGESET",e.getChangeset());for(var i in t.tags)if(t.tags.hasOwnProperty(i)){if(r=t.tags[i],void 0===r||null===r)continue;s+=o.replace("KEY",i).replace("VALUE",t.tags[i])}return n=n.replace("TAGS",s),n=n.replace("LNG",t.lng),n=n.replace("LAT",t.lat)},this.serialiseXmlToString=function(e){return this.serializer.serializeToString(e)},this.getTagsFromChildren=function(e){var t,r;r={};for(var n=0;n<e.children.length;n++)t=e.children[n],"tag"===t.tagName&&(r[t.getAttribute("k")]=t.getAttribute("v"));return r},this.getNameFromTags=function(e){for(var t,r=0;r<e.children.length;r++)if(t=e.children[r],"tag"===t.tagName&&"name"===t.getAttribute("k"))return t.getAttribute("v")},this.relationXmlToGeoJSON=function(e,t){var r=this,n=[],o=[],s={type:"FeatureCollection",properties:{id:e},options:{},members:[],features:n,relations:o},i=t.getElementById(e);s.properties.visible=i.getAttribute("visible"),s.properties.version=i.getAttribute("version"),s.properties.changeset=i.getAttribute("changeset"),s.properties.timestamp=i.getAttribute("timestamp"),s.properties.user=i.getAttribute("user"),s.properties.uid=i.getAttribute("uid");var a,u,l,g,c,f,d,p,h;for(u=0;u<i.children.length;u++)if(a=i.children[u],"member"===a.tagName)if(p={type:a.getAttribute("type"),ref:a.getAttribute("ref"),role:a.getAttribute("role")},s.members.push(p),h=t.getElementById(a.getAttribute("ref")),c=r.getTagsFromChildren(h),p.name=c.name,"way"===h.tagName){f=[],d={type:"Feature",properties:c,id:a.getAttribute("ref"),geometry:{type:"LineString",coordinates:f}};for(var m=0;m<h.children.length;m++)l=h.children[m],"nd"===l.tagName&&(g=t.getElementById(l.getAttribute("ref")),f.push([parseFloat(g.getAttribute("lon")),parseFloat(g.getAttribute("lat"))]));n.push(d)}else"node"===h.tagName?(d={type:"Feature",properties:c,id:a.getAttribute("ref"),geometry:{type:"Point",coordinates:[parseFloat(h.getAttribute("lon")),parseFloat(h.getAttribute("lat"))]}},n.push(d)):"relation"===h.tagName&&(p.tags=c);return s.tags=r.getTagsFromChildren(i),s},this.encodeXML=function(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")},this.relationGeoJSONToXml=function(t){var r,n=t.properties,o=t.members,s=e,i='<?xml version="1.0" encoding="UTF-8"?>\n';for(i+='<osm version="0.6" generator="angular-osm 0.2" copyright="OpenStreetMap and contributors" attribution="http://www.openstreetmap.org/copyright" license="http://opendatacommons.org/licenses/odbl/1-0/">\n',i+=' <relation id="'+n.id+'" visible="'+n.visible+'" ',i+='version="'+n.version+'" ',i+='changeset="'+s.getChangeset()+'" timestamp="'+(new Date).toISOString()+'" ',i+='user="'+s.getUserName()+'" uid="'+n.uid+'">\n',r=0;r<o.length;r++)i+=' <member type="'+o[r].type+'" ',i+='ref="'+o[r].ref,i+="relation"===o[r].type?'" role="'+o[r].role+'"/>\n':'" role="'+o[r].role+'"/>\n';var a=t.tags;for(var u in a)i+=' <tag k="'+u+'" v="'+this.encodeXML(a[u])+'"/>\n';return i+=" </relation>\n",i+="</osm>"},this.sortRelationMembers=function(e){var t,r,n,o,s,i,a,u,l,g,c,f,d=e.members,p=e.features,h=[],m=function(e){h.splice(0,0,e)},v=function(e){h.push(e)},y=function(e){return p[e].geometry.coordinates},b=!1;for(r=0;r<d.length;r++)if(n=d[r],"way"===n.type){for(c=!1,s=0;s<h.length;s++)h[s].ref===n.ref&&(c=!0);if(!c){for(0===h.length&&(h.push(n),u=y(r),l=u[0],g=u[u.length-1]),f=b=!1,o=0;o<p.length;o++)if(t=p[o],"LineString"===t.geometry.type){for(c=!1,s=0;s<h.length;s++)h[s].ref===t.id&&(c=!0);c||(u=y(o),i=u[0],a=u[u.length-1],l[0]!==a[0]||l[1]!==a[1]?g[0]!==i[0]||g[1]!==i[1]?l[0]!==i[0]||l[1]!==i[1]?g[0]!==a[0]||g[1]!==a[1]||(v(d[o]),g=i,b=!0):(m(d[o]),l=a,f=!0):(v(d[o]),g=a,b=!0):(m(d[o]),l=i,f=!0))}f||b||(console.log("not found connected ways for "+n.ref),console.log(l),console.log(g))}}else h.push(n);if(d.length===h.length){e.members=h;var A={loaded:!1},S=function(e){if(!A.loaded)for(var t=0;t<p.length;t++)A[p[t].id]=p[t];return A[e]};e.features=[];for(var N=0;N<h.length;N++)e.features.push(S(h[N].ref))}else console.error("can t sort this relation");return e},this.getNodesInJSON=function(t,r){e.setNodes(t);var n={};return void 0!==r&&(n.flatProperties=r),osmtogeojson(t,n)},this.yqlJSON=function(e){var t,r,n=$q.defer();return r={params:{q:"select * from json where url='"+e+"';",format:"json"}},t="http://query.yahooapis.com/v1/public/yql",$http.get(t,r).then(function(e){null===e.data.query.results?n.resolve([]):n.resolve(e.data.query.results.json)},function(e){n.reject(e)}),n.promise},this.getElementTypeFromFeature=function(e){var t=e.geometry.type;return"LineString"===t?"way":"Point"===t?"node":void console.error("not supported type "+t)}}Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=r}])}); | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("angular-base64"),require("ngstorage")):"function"==typeof define&&define.amd?define(["angular-base64","ngstorage"],t):"object"==typeof exports?exports.name=t(require("angular-base64"),require("ngstorage")):(e["angular-osm"]=e["angular-osm"]||{},e["angular-osm"].name=t(e["angular-base64"],e.ngstorage))}(this,function(e,t){return function(e){function t(n){if(r[n])return r[n].exports;var o=r[n]={exports:{},id:n,loaded:!1};return e[n].call(o.exports,o,o.exports,t),o.loaded=!0,o.exports}var r={};return t.m=e,t.c=r,t.p="",t(0)}([function(e,t,r){e.exports=r(1)},function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{"default":e}}Object.defineProperty(t,"__esModule",{value:!0});var o=r(2),s=(n(o),r(3)),i=n(s),a=r(4),u=n(a),l=r(7),c=n(l),h=angular.module("osm.api",[u["default"].name,c["default"].name,"base64"]).service("osmAPI",i["default"]).provider("osmAPI",function(){this.options={url:"http://api.openstreetmap.org/api"},this.$get=function(e,t,r,n,o){return new i["default"](e,t,r,n,o,this.options)},this.$get.$inject=["$base64","$http","$q","osmSettingsService","osmUtilsService"]});t["default"]=h},function(t,r){t.exports=e},function(e,t){"use strict";function r(e,t,r,o,s,i){function a(e){try{return e instanceof HTMLElement}catch(t){return"object"===("undefined"==typeof e?"undefined":n(e))&&1===e.nodeType&&"object"===n(e.style)&&"object"===n(e.ownerDocument)}}this.url=i.url,this.validateCredentials=function(){var e=r.defer();return this.getUserDetails().then(function(t){t.osm.user&&o.setUserID(t.osm.user._id),e.resolve(void 0!==t.osm.user)},function(t){e.reject(t)}),e.promise},this.setCredentials=function(t,r){o.setUserName(t);var n=e.encode(t+":"+r);return o.setCredentials(n),n},this.getCredentials=function(){return o.getCredentials()},this.getAuthorization=function(){return"Basic "+o.getCredentials()},this.clearCredentials=function(){o.setCredentials("")},this.setOauth=function(e){this._oauth=e},this.getOauth=function(){return this._oauth},this.xhr=function(e){var n=r.defer(),o=void 0,i=this._oauth;return i?(e.path="/api"+e.path,e.data&&(e.body=e.data,e.data=void 0),o=this._oauth.xhr(e)):(e.url=this.url+e.path,e.headers={Authorization:this.getAuthorization()},o=t(e)),o.then(function(e){var t,r=function(e){if(!e)return e;if(e.substr){if("<?xml"===e.substr(0,5))return s.xml2js(e)}else if(a(e))return s.x2js.dom2js(e);return e};t=i?e:e.data,n.resolve(r(t))},function(e){n.reject(e)}),n.promise},this.getAuthenticated=function(e,t){var r=angular.copy(t);return r||(r={}),r.method="GET",r.path=e,this.xhr(r)},this.get=function(e,n){var o=r.defer(),i=this.url+e;return t.get(i,n).then(function(e){o.resolve(s.xml2js(e.data))},function(e){o.reject(e)}),o.promise},this.put=function(e,t,r){r||(r={});var n=angular.copy(r);return n.method="PUT",n.path=e,n.data=s.js2xml(t),this.xhr(n)},this["delete"]=function(e,t){t||(t={});var r=angular.copy(t);return r.method="DELETE",r.path=e,this.xhr(r)},this.createChangeset=function(e){var t=r.defer(),n={osm:{changeset:{tag:[{_k:"created_by",_v:"Angular-OSM"},{_k:"comment",_v:e}]}}};return this.put("/0.6/changeset/create",n).then(function(e){o.setChangeset(e),t.resolve(e)}),t.promise},this.getLastOpenedChangesetId=function(){var e=r.defer(),t={params:{user:o.getUserID(),open:!0}};return this.get("/0.6/changesets",t).then(function(t){var r=t.osm.changeset;r.length>0?(o.setChangeset(r[0].id),e.resolve(r[0].id)):r._id?(o.setChangeset(r._id),e.resolve(r._id)):(o.setChangeset(),e.resolve())}),e.promise},this.closeChangeset=function(){var e=o.getChangeset();return this.put("/0.6/changeset/"+e+"/close").then(function(e){return o.setChangeset(),e})},this.getUserById=function(e){return this.getAuthenticated("/0.6/user/"+e)},this.getUserDetails=function(){return this.getAuthenticated("/0.6/user/details")},this.getUserPreferences=function(){return this.getAuthenticated("/0.6/user/preferences")},this.putUserPreferences=function(e,t){return this.put("/0.6/user/preferences/"+e,t)},this.getMap=function(e){return this.get("/0.6/map?bbox="+e)},this.getMapGeoJSON=function(e){var t=this,n=r.defer();return t.getMap(e).then(function(e){var t=s.js2geojson(e);n.resolve(t)},function(e){n.reject(e)}),n.promise},this.getNotes=function(e){var t="/0.6/notes?bbox="+e;return this.get(t)},this.createNode=function(e){return this.put("/0.6/node/create",e)},this.getNode=function(e){return this.get("/0.6/node/"+e)},this.deleteNode=function(e){return this["delete"]("/0.6/node/"+e)},this.createWay=function(e){return this.put("/0.6/way/create",e)},this.getWay=function(e){return this.get("/0.6/way/"+e)},this.deleteWay=function(e){return this["delete"]("/0.6/way/"+e)},this.createRelation=function(e){return this.put("/0.6/relation/create",e)},this.getRelation=function(e){return this.get("/0.6/relation/"+e)},this.deleteRelation=function(e){return this["delete"]("/0.6/relation/"+e)}}Object.defineProperty(t,"__esModule",{value:!0});var n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol?"symbol":typeof e};t["default"]=r},function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{"default":e}}Object.defineProperty(t,"__esModule",{value:!0});var o=r(5),s=n(o),i=r(6),a=n(i),u=a["default"]?a["default"].name:"ngStorage",l=angular.module("osm.settings",[u]).service("osmSettingsService",s["default"]);t["default"]=l},function(e,t){"use strict";function r(e){this.localStorage=e.$default({userName:"",userID:"",credentials:"",changeset:""}),this.getUserName=function(){return this.localStorage.userName},this.setUserName=function(e){this.localStorage.userName=e},this.getUserID=function(){return this.localStorage.userID},this.setUserID=function(e){this.localStorage.userID=e},this.getCredentials=function(){return this.localStorage.credentials},this.setCredentials=function(e){this.localStorage.credentials=e},this.getChangeset=function(){return this.localStorage.changeset},this.setChangeset=function(e){this.localStorage.changeset=e},this.getOsmAuth=function(){return this.localStorage.osmAuth},this.setOsmAuth=function(e){this.localStorage.osmAuth=e}}Object.defineProperty(t,"__esModule",{value:!0}),r.$inject=["$localStorage"],t["default"]=r},function(e,r){e.exports=t},function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{"default":e}}Object.defineProperty(t,"__esModule",{value:!0});var o=r(8),s=n(o),i=r(4),a=n(i),u=r(9),l=n(u),c=angular.module("osm.utils",[a["default"].name,l["default"].name]).service("osmUtilsService",s["default"]);t["default"]=c},function(e,t){"use strict";function r(e,t,r){this.relationToGeoJSON=function(e,t){var r=this,n=[],o=[],s={type:"FeatureCollection",properties:{id:e},options:{},members:[],features:n,relations:o},t=relationXML.getElementById(e);s.properties.visible=t.getAttribute("visible"),s.properties.version=t.getAttribute("version"),s.properties.changeset=t.getAttribute("changeset"),s.properties.timestamp=t.getAttribute("timestamp"),s.properties.user=t.getAttribute("user"),s.properties.uid=t.getAttribute("uid");var i,a,u,l,c,h,f,g,d;for(a=0;a<t.children.length;a++)if(i=t.children[a],"member"===i.tagName)if(g={type:i.getAttribute("type"),ref:i.getAttribute("ref"),role:i.getAttribute("role")},s.members.push(g),d=relationXML.getElementById(i.getAttribute("ref")),c=r.getTagsFromChildren(d),g.name=c.name,"way"===d.tagName){h=[],f={type:"Feature",properties:c,id:i.getAttribute("ref"),geometry:{type:"LineString",coordinates:h}};for(var p=0;p<d.children.length;p++)u=d.children[p],"nd"===u.tagName&&(l=relationXML.getElementById(u.getAttribute("ref")),h.push([parseFloat(l.getAttribute("lon")),parseFloat(l.getAttribute("lat"))]));n.push(f)}else"node"===d.tagName?(f={type:"Feature",properties:c,id:i.getAttribute("ref"),geometry:{type:"Point",coordinates:[parseFloat(d.getAttribute("lon")),parseFloat(d.getAttribute("lat"))]}},n.push(f)):"relation"===d.tagName&&(g.tags=c);return s.tags=r.getTagsFromChildren(t),s},this.encodeXML=function(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")},this.relationGeoJSONToXml=function(e){var r,n=e.properties,o=e.members,s=t,i='<?xml version="1.0" encoding="UTF-8"?>\n';for(i+='<osm version="0.6" generator="angular-osm 0.2" copyright="OpenStreetMap and contributors" attribution="http://www.openstreetmap.org/copyright" license="http://opendatacommons.org/licenses/odbl/1-0/">\n',i+=' <relation id="'+n.id+'" visible="'+n.visible+'" ',i+='version="'+n.version+'" ',i+='changeset="'+s.getChangeset()+'" timestamp="'+(new Date).toISOString()+'" ',i+='user="'+s.getUserName()+'" uid="'+n.uid+'">\n',r=0;r<o.length;r++)i+=' <member type="'+o[r].type+'" ',i+='ref="'+o[r].ref,i+="relation"===o[r].type?'" role="'+o[r].role+'"/>\n':'" role="'+o[r].role+'"/>\n';var a=e.tags;for(var u in a)i+=' <tag k="'+u+'" v="'+this.encodeXML(a[u])+'"/>\n';return i+=" </relation>\n",i+="</osm>"},this.sortRelationMembers=function(e){var t,r,n,o,s,i,a,u,l,c,h,f,g=e.members,d=e.features,p=[],m=function(e){p.splice(0,0,e)},v=function(e){p.push(e)},y=function(e){return d[e].geometry.coordinates},b=!1;for(r=0;r<g.length;r++)if(n=g[r],"way"===n.type){for(h=!1,s=0;s<p.length;s++)p[s].ref===n.ref&&(h=!0);if(!h){for(0===p.length&&(p.push(n),u=y(r),l=u[0],c=u[u.length-1]),f=b=!1,o=0;o<d.length;o++)if(t=d[o],"LineString"===t.geometry.type){for(h=!1,s=0;s<p.length;s++)p[s].ref===t.id&&(h=!0);h||(u=y(o),i=u[0],a=u[u.length-1],l[0]!==a[0]||l[1]!==a[1]?c[0]!==i[0]||c[1]!==i[1]?l[0]!==i[0]||l[1]!==i[1]?c[0]!==a[0]||c[1]!==a[1]||(v(g[o]),c=i,b=!0):(m(g[o]),l=a,f=!0):(v(g[o]),c=a,b=!0):(m(g[o]),l=i,f=!0))}f||b||(console.log("not found connected ways for "+n.ref),console.log(l),console.log(c))}}else p.push(n);if(g.length===p.length){e.members=p;var j={loaded:!1},S=function(e){if(!j.loaded)for(var t=0;t<d.length;t++)j[d[t].id]=d[t];return j[e]};e.features=[];for(var _=0;_<p.length;_++)e.features.push(S(p[_].ref))}else console.error("can t sort this relation");return e},this.x2js=r,this.xml2js=function(e){return r.xml2js(e)},this.js2xml=function(e){return r.js2xml(e)},this.yqlJSON=function(t){var r,n,o=$q.defer();return n={params:{q:"select * from json where url='"+t+"';",format:"json"}},r="http://query.yahooapis.com/v1/public/yql",e.get(r,n).then(function(e){null===e.data.query.results?o.resolve([]):o.resolve(e.data.query.results.json)},function(e){o.reject(e)}),o.promise},this.getElementTypeFromFeature=function(e){var t=e.geometry.type;return"LineString"===t?"way":"Point"===t?"node":void console.error("not supported type "+t)}}Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=r},function(e,t){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=angular.module("osm.x2js",[]).provider("osmx2js",function(){this.options={},this.$get=function(){return new X2JS(this.options)}});t["default"]=r}])}); |
1141
dist/osm-full.js
@@ -10,3 +10,3 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
root["angular-osm"] = root["angular-osm"] || {}, root["angular-osm"]["name"] = factory(root["angular-base64"], root["ngstorage"], root["angular"], root["osm-auth"]); | ||
})(this, function(__WEBPACK_EXTERNAL_MODULE_2__, __WEBPACK_EXTERNAL_MODULE_6__, __WEBPACK_EXTERNAL_MODULE_9__, __WEBPACK_EXTERNAL_MODULE_12__) { | ||
})(this, function(__WEBPACK_EXTERNAL_MODULE_2__, __WEBPACK_EXTERNAL_MODULE_6__, __WEBPACK_EXTERNAL_MODULE_10__, __WEBPACK_EXTERNAL_MODULE_13__) { | ||
return /******/ (function(modules) { // webpackBootstrap | ||
@@ -60,7 +60,7 @@ /******/ // The module cache | ||
var _angular = __webpack_require__(9); | ||
var _angular = __webpack_require__(10); | ||
var _angular2 = _interopRequireDefault(_angular); | ||
var _oauth = __webpack_require__(10); | ||
var _oauth = __webpack_require__(11); | ||
@@ -73,7 +73,7 @@ var _oauth2 = _interopRequireDefault(_oauth); | ||
var _overpass = __webpack_require__(13); | ||
var _overpass = __webpack_require__(14); | ||
var _overpass2 = _interopRequireDefault(_overpass); | ||
var _taginfo = __webpack_require__(15); | ||
var _taginfo = __webpack_require__(16); | ||
@@ -86,5 +86,9 @@ var _taginfo2 = _interopRequireDefault(_taginfo); | ||
var _nominatim = __webpack_require__(18); | ||
var _nominatim2 = _interopRequireDefault(_nominatim); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
_angular2.default.module('osm', [_settings2.default.name, _api2.default.name, _overpass2.default.name, _taginfo2.default.name, _oauth2.default.name]); | ||
_angular2.default.module('osm', [_settings2.default.name, _api2.default.name, _overpass2.default.name, _taginfo2.default.name, _oauth2.default.name, _nominatim2.default.name]); | ||
@@ -121,3 +125,11 @@ /***/ }, | ||
var osmAPIModule = angular.module('osm.api', [_settings2.default.name, _utils2.default.name, 'base64']).service('osmAPI', _api2.default); | ||
var osmAPIModule = angular.module('osm.api', [_settings2.default.name, _utils2.default.name, 'base64']).service('osmAPI', _api2.default).provider('osmAPI', function osmAPIProvider() { | ||
this.options = { | ||
url: 'http://api.openstreetmap.org/api' | ||
}; | ||
this.$get = function osmAPIFactory($base64, $http, $q, osmSettingsService, osmUtilsService) { | ||
return new _api2.default($base64, $http, $q, osmSettingsService, osmUtilsService, this.options); | ||
}; | ||
this.$get.$inject = ['$base64', '$http', '$q', 'osmSettingsService', 'osmUtilsService']; | ||
}); | ||
@@ -147,2 +159,4 @@ exports.default = osmAPIModule; | ||
* @name osm.oauth.osmAuthService | ||
* @description The main idea is use geojson object where it is possible | ||
* for the rest of the API (changeset, ...) it's XML2JS that is used so always expect objects. | ||
* @param {any} $base64 | ||
@@ -153,4 +167,7 @@ * @param {any} $http | ||
*/ | ||
osmAPI.$inject = ['$base64', '$http', '$q', 'osmSettingsService', 'osmUtilsService']; | ||
function osmAPI($base64, $http, $q, osmSettingsService, osmUtilsService) { | ||
function osmAPI($base64, $http, $q, osmSettingsService, osmUtilsService, options) { | ||
this.url = options.url; | ||
// ------------------ CREDENTIALS ----------------- | ||
/** | ||
@@ -167,8 +184,6 @@ * @ngdoc method | ||
this.getUserDetails().then(function (data) { | ||
var parsed = osmUtilsService.parseXml(data); | ||
var users = parsed.getElementsByTagName('user'); | ||
if (users.length === 1) { | ||
osmSettingsService.setUserID(users[0].id); | ||
if (data.osm.user) { | ||
osmSettingsService.setUserID(data.osm.user._id); | ||
} | ||
deferred.resolve(users.length > 0); | ||
deferred.resolve(data.osm.user !== undefined); | ||
}, function (error) { | ||
@@ -224,4 +239,102 @@ deferred.reject(error); | ||
}; | ||
/** | ||
* @ngdoc method | ||
* @name setOauth | ||
* @description use oauth object to call API | ||
* @methodOf osm.api.osmAPI | ||
*/ | ||
this.setOauth = function setOauth(oauth) { | ||
this._oauth = oauth; | ||
}; | ||
/** | ||
* @ngdoc method | ||
* @name setOauth | ||
* @description use oauth object to call API | ||
* @methodOf osm.api.osmAPI | ||
* @return {Object} oauth | ||
*/ | ||
this.getOauth = function getOauth() { | ||
return this._oauth; | ||
}; | ||
// ------------------ INTERNAL CALL SERVER (API) ----------------- | ||
function isElement(obj) { | ||
try { | ||
//Using W3 DOM2 (works for FF, Opera and Chrom) | ||
return obj instanceof HTMLElement; | ||
} catch (e) { | ||
//Browsers not supporting W3 DOM2 don't have HTMLElement and | ||
//an exception is thrown and we end up here. Testing some | ||
//properties that all elements have. (works on IE7) | ||
return (typeof obj === 'undefined' ? 'undefined' : _typeof(obj)) === "object" && obj.nodeType === 1 && _typeof(obj.style) === "object" && _typeof(obj.ownerDocument) === "object"; | ||
} | ||
} | ||
/** | ||
* @ngdoc method | ||
* @name xhr | ||
* @description call the API | ||
* @param {Object} options | ||
* @comment | ||
* ``` | ||
var options = { | ||
method: 'GET', // POST, DELETE, PUT | ||
path: '/0.6/changesets', //without the /api | ||
data: content //if you need a payload | ||
}; | ||
osmAPI.xhr(options); | ||
``` | ||
* @methodOf osm.api.osmAPI | ||
* @return {Object} oauth | ||
*/ | ||
this.xhr = function (options) { | ||
var deferred = $q.defer(); | ||
var promise = void 0; | ||
var hasOauth = this._oauth; | ||
if (hasOauth) { | ||
options.path = '/api' + options.path; | ||
if (options.data) { | ||
options.body = options.data; | ||
options.data = undefined; | ||
} | ||
promise = this._oauth.xhr(options); | ||
} else { | ||
options.url = this.url + options.path; | ||
options.headers = { | ||
Authorization: this.getAuthorization() | ||
}; | ||
promise = $http(options); | ||
} | ||
promise.then(function (data) { | ||
var d; | ||
var t = function t(d) { | ||
if (!d) { | ||
return d; | ||
} | ||
if (d.substr) { | ||
if (d.substr(0, 5) === '<?xml') { | ||
return osmUtilsService.xml2js(d); | ||
} | ||
} else if (isElement(d)) { | ||
return osmUtilsService.x2js.dom2js(d); | ||
} | ||
return d; | ||
}; | ||
if (hasOauth) { | ||
d = data; | ||
} else { | ||
d = data.data; | ||
} | ||
deferred.resolve(t(d)); | ||
}, function (error) { | ||
deferred.reject(error); | ||
}); | ||
return deferred.promise; | ||
}; | ||
/** | ||
* @ngdoc method | ||
* @name getAuthenticated | ||
@@ -234,7 +347,9 @@ * @description send a get request to OSM with | ||
this.getAuthenticated = function (method, config) { | ||
if (config === undefined) { | ||
config = {}; | ||
var _config = angular.copy(config); | ||
if (!_config) { | ||
_config = {}; | ||
} | ||
config.headers = { Authorization: this.getAuthorization() }; | ||
return this.get(method, config); | ||
_config.method = 'GET'; | ||
_config.path = method; | ||
return this.xhr(_config); | ||
}; | ||
@@ -253,7 +368,7 @@ /** | ||
var self = this; | ||
var url = osmSettingsService.getOSMAPI() + method; | ||
var url = this.url + method; | ||
$http.get(url, config).then(function (data) { | ||
deferred.resolve(data.data); | ||
}, function (data) { | ||
deferred.reject(data); | ||
deferred.resolve(osmUtilsService.xml2js(data.data)); | ||
}, function (error) { | ||
deferred.reject(error); | ||
}); | ||
@@ -273,16 +388,10 @@ return deferred.promise; | ||
this.put = function (method, content, config) { | ||
var deferred = $q.defer(); | ||
var self = this; | ||
if (config === undefined) { | ||
if (!config) { | ||
config = {}; | ||
} | ||
config.headers = { Authorization: this.getAuthorization() }; | ||
var url = osmSettingsService.getOSMAPI() + method; | ||
$http.put(url, content, config).then(function (data) { | ||
deferred.resolve(data.data); | ||
}, function (data) { | ||
deferred.reject(data); | ||
}); | ||
return deferred.promise; | ||
var _config = angular.copy(config); | ||
_config.method = 'PUT'; | ||
_config.path = method; | ||
_config.data = osmUtilsService.js2xml(content); | ||
return this.xhr(_config); | ||
}; | ||
@@ -299,18 +408,13 @@ /** | ||
this.delete = function (method, config) { | ||
var deferred = $q.defer(); | ||
var self = this; | ||
if (config === undefined) { | ||
if (!config) { | ||
config = {}; | ||
} | ||
config.headers = { Authorization: this.getAuthorization() }; | ||
config.url = osmSettingsService.getOSMAPI() + method; | ||
config.method = 'delete'; | ||
$http(config).then(function (data) { | ||
deferred.resolve(data.data); | ||
}, function (data) { | ||
deferred.reject(data); | ||
}); | ||
return deferred.promise; | ||
var _config = angular.copy(config); | ||
_config.method = 'DELETE'; | ||
_config.path = method; | ||
return this.xhr(_config); | ||
}; | ||
// ------------------ CHANGESET ----------------- | ||
/** | ||
@@ -325,4 +429,7 @@ * @ngdoc method | ||
var deferred = $q.defer(); | ||
var changeset = '<osm><changeset><tag k="created_by" v="Angular-OSM"/><tag k="comment" v="'; | ||
changeset += comment + '"/></changeset></osm>'; | ||
var changeset = { osm: { | ||
changeset: { | ||
tag: [{ _k: 'created_by', _v: 'Angular-OSM' }, { _k: 'comment', _v: comment }] | ||
} | ||
} }; | ||
this.put('/0.6/changeset/create', changeset).then(function (data) { | ||
@@ -347,7 +454,9 @@ osmSettingsService.setChangeset(data); | ||
this.get('/0.6/changesets', config).then(function (data) { | ||
var parsed = osmUtilsService.parseXml(data); | ||
var changesets = parsed.getElementsByTagName('changeset'); | ||
var changesets = data.osm.changeset; | ||
if (changesets.length > 0) { | ||
osmSettingsService.setChangeset(changesets[0].id); | ||
deferred.resolve(changesets[0].id); | ||
} else if (changesets._id) { | ||
osmSettingsService.setChangeset(changesets._id); | ||
deferred.resolve(changesets._id); | ||
} else { | ||
@@ -374,4 +483,19 @@ osmSettingsService.setChangeset(); | ||
}; | ||
// ------------------ USER API ----------------- | ||
/** | ||
* @ngdoc method | ||
* @name getUserById | ||
* @methodOf osm.api.osmAPI | ||
* @param {string} id of the user | ||
* @returns {Promise} $http.get response | ||
* /0.6/user/#id | ||
*/ | ||
this.getUserById = function (id) { | ||
return this.getAuthenticated('/0.6/user/' + id); | ||
}; | ||
/** | ||
* @ngdoc method | ||
* @name getUserDetails | ||
@@ -387,2 +511,28 @@ * @methodOf osm.api.osmAPI | ||
* @ngdoc method | ||
* @name getUserPreferences | ||
* @methodOf osm.api.osmAPI | ||
* @returns {Promise} $http.get response | ||
* /0.6/user/preferences | ||
*/ | ||
this.getUserPreferences = function () { | ||
return this.getAuthenticated('/0.6/user/preferences'); | ||
}; | ||
/** | ||
* @ngdoc method | ||
* @name putUserPreferences | ||
* @methodOf osm.api.osmAPI | ||
* @param {string} key the preference key | ||
* @param {string} value the preference value | ||
* @returns {Promise} $http.get response | ||
* /0.6/user/preferences | ||
*/ | ||
this.putUserPreferences = function (key, value) { | ||
return this.put('/0.6/user/preferences/' + key, value); | ||
}; | ||
//------------------ MAP DATA ------------------------- | ||
/** | ||
* @ngdoc method | ||
* @name getMap | ||
@@ -405,2 +555,21 @@ * @methodOf osm.api.osmAPI | ||
* @ngdoc method | ||
* @name getMapGeoJSON | ||
* @methodOf osm.api.osmAPI | ||
* @param {string} bbox the bounding box | ||
* @returns {Promise} $http.get response | ||
*/ | ||
this.getMapGeoJSON = function (bbox) { | ||
var self = this; | ||
var deferred = $q.defer(); | ||
self.getMap(bbox).then(function (nodes) { | ||
var geojsonNodes = osmUtilsService.js2geojson(nodes); | ||
deferred.resolve(geojsonNodes); | ||
}, function (error) { | ||
deferred.reject(error); | ||
}); | ||
return deferred.promise; | ||
}; | ||
/** | ||
* @ngdoc method | ||
* @name getNotes | ||
@@ -414,114 +583,148 @@ * @methodOf osm.api.osmAPI | ||
top is the latitude of the top (northernmost) side of the bounding box. | ||
* @param {string} format Currently the format rss, xml, json and gpx are supported. | ||
* @returns {Promise} $http.get response | ||
* /0.6/notes[.format]?bbox=bbox | ||
*/ | ||
this.getNotes = function (bbox, format) { | ||
var url = '/0.6/notes'; | ||
if (format) { | ||
url += '.' + format; | ||
} | ||
url += '?bbox=' + bbox; | ||
this.getNotes = function (bbox) { | ||
var url = '/0.6/notes?bbox=' + bbox; | ||
return this.get(url); | ||
}; | ||
//------------------ ELEMENTS: Node ---------------- | ||
/** | ||
* @ngdoc method | ||
* @name updateNode | ||
* @name createNode | ||
* @methodOf osm.api.osmAPI | ||
* @param {Object} currentNode geojson | ||
* @param {Object} updatedNode geojson | ||
* @param {Object/string} node | ||
var node = {osm: {node: { | ||
_changeset: '12', _lat: '...', _lon: '...', | ||
tags: [ | ||
{_k: '...', _v: '...'} | ||
] | ||
}}}; | ||
* @returns {Promise} $http.put response | ||
* PUT /0.6/node/create | ||
*/ | ||
this.createNode = function (node) { | ||
return this.put('/0.6/node/create', node); | ||
}; | ||
/** | ||
* @ngdoc method | ||
* @name getNode | ||
* @methodOf osm.api.osmAPI | ||
* @param {string} id | ||
* @returns {Promise} $http.get response | ||
* /0.6/map?bbox=bbox | ||
* GET /0.6/node/#id | ||
*/ | ||
this.updateNode = function (currentNode, updatedNode) { | ||
//we need to do the diff and build the xml | ||
//first try to find the node by id | ||
var nodes = osmSettingsService.getNodes(); | ||
var node = nodes.getElementById(currentNode.properties.id); | ||
var deferred = $q.defer(); //only for errors | ||
if (node === null) { | ||
deferred.reject({ | ||
msg: 'can t find node', | ||
currentNode: currentNode, | ||
updatedNode: updatedNode, | ||
osmNode: node | ||
}); | ||
return deferred.promise; | ||
} | ||
var tag; | ||
node.setAttribute('changeset', osmSettingsService.getChangeset()); | ||
node.setAttribute('user', osmSettingsService.getUserName()); | ||
while (node.getElementsByTagName('tag')[0]) { | ||
node.removeChild(node.getElementsByTagName('tag')[0]); | ||
} | ||
var osm = document.createElement('osm'); | ||
var value; | ||
osm.appendChild(node); | ||
for (var property in updatedNode.properties.tags) { | ||
if (updatedNode.properties.tags.hasOwnProperty(property)) { | ||
value = updatedNode.properties.tags[property]; | ||
if (value === undefined) { | ||
continue; | ||
} | ||
tag = document.createElement('tag'); | ||
tag.setAttribute('k', property); | ||
tag.setAttribute('v', value); | ||
node.appendChild(tag); | ||
} | ||
} | ||
var nodeType; | ||
if (updatedNode.geometry.type === 'Polygon') { | ||
nodeType = 'way'; | ||
} else if (updatedNode.geometry.type === 'Point') { | ||
nodeType = 'node'; | ||
} else if (updatedNode.geometry.type === 'LineString') { | ||
nodeType = 'way'; | ||
} else { | ||
deferred.reject({ | ||
msg: 'geojson type not supported', | ||
currentNode: currentNode, | ||
updatedNode: updatedNode, | ||
osmNode: node | ||
}); | ||
return deferred.promise; | ||
} | ||
//put request !! | ||
var url = '/0.6/' + nodeType + '/' + currentNode.properties.id; | ||
return this.put(url, osm.outerHTML); | ||
this.getNode = function (id) { | ||
return this.get('/0.6/node/' + id); | ||
}; | ||
/** | ||
* @ngdoc method | ||
* @name createNode | ||
* @name deleteNode | ||
* @methodOf osm.api.osmAPI | ||
* @param {Object/string} node as xml or geojson | ||
* @param {string} id | ||
* @returns {Promise} $http.delete response | ||
* DELETE /0.6/node/#id | ||
*/ | ||
this.deleteNode = function (id) { | ||
return this.delete('/0.6/node/' + id); | ||
}; | ||
//------------------ ELEMENTS: WAY ---------------- | ||
/** | ||
* @ngdoc method | ||
* @name createWay | ||
* @methodOf osm.api.osmAPI | ||
* @param {Object/string} way | ||
var way = {osm: {way: { | ||
_changeset: '12', _lat: '...', _lon: '...', | ||
tags: [ | ||
{_k: '...', _v: '...'} | ||
], | ||
nd: [ | ||
{_ref: '123'}, | ||
{_ref: '456'}, | ||
] | ||
}}}; | ||
* @returns {Promise} $http.put response | ||
* /0.6/node/create | ||
* PUT /0.6/way/create | ||
*/ | ||
this.createNode = function (node) { | ||
var xmlnode = node; | ||
if ((typeof node === 'undefined' ? 'undefined' : _typeof(node)) === 'object') { | ||
xmlnode = osmUtilsService.createNodeXML(node); | ||
} | ||
return this.put('/0.6/node/create', xmlnode); | ||
this.createWay = function (way) { | ||
return this.put('/0.6/way/create', way); | ||
}; | ||
/** | ||
* @ngdoc method | ||
* @name getMapGeoJSON | ||
* @name getWay | ||
* @methodOf osm.api.osmAPI | ||
* @param {string} bbox the bounding box | ||
* @param {string} id | ||
* @returns {Promise} $http.get response | ||
* GET /0.6/way/#id | ||
*/ | ||
this.getMapGeoJSON = function (bbox) { | ||
var self = this; | ||
var deferred = $q.defer(); | ||
self.getMap(bbox).then(function (strNodes) { | ||
var xmlNodes = osmUtilsService.parseXml(strNodes); | ||
var geojsonNodes = osmUtilsService.getNodesInJSON(xmlNodes); | ||
deferred.resolve(geojsonNodes); | ||
}, function (error) { | ||
deferred.reject(error); | ||
}); | ||
return deferred.promise; | ||
this.getWay = function (id) { | ||
return this.get('/0.6/way/' + id); | ||
}; | ||
/** | ||
* @ngdoc method | ||
* @name deleteWay | ||
* @methodOf osm.api.osmAPI | ||
* @param {string} id | ||
* @returns {Promise} $http.delete response | ||
* DELETE /0.6/way/#id | ||
*/ | ||
this.deleteWay = function (id) { | ||
return this.delete('/0.6/way/' + id); | ||
}; | ||
//------------------ ELEMENTS: RELATION ---------------- | ||
/** | ||
* @ngdoc method | ||
* @name createRelation | ||
* @methodOf osm.api.osmAPI | ||
* @param {Object/string} relation | ||
var relation = {osm: {relation: { | ||
_changeset: '12', _lat: '...', _lon: '...', | ||
tags: [ | ||
{_k: '...', _v: '...'} | ||
], | ||
member: [ | ||
{_type: 'node', _role: 'stop', 'ref': '123'}, | ||
{_type: 'way', 'ref': '234'} | ||
] | ||
}}}; | ||
* @returns {Promise} $http.put response | ||
* PUT /0.6/relation/create | ||
*/ | ||
this.createRelation = function (relation) { | ||
return this.put('/0.6/relation/create', relation); | ||
}; | ||
/** | ||
* @ngdoc method | ||
* @name getRelation | ||
* @methodOf osm.api.osmAPI | ||
* @param {string} id | ||
* @returns {Promise} $http.get response | ||
* GET /0.6/relation/#id | ||
*/ | ||
this.getRelation = function (id) { | ||
return this.get('/0.6/relation/' + id); | ||
}; | ||
/** | ||
* @ngdoc method | ||
* @name deleteRelation | ||
* @methodOf osm.api.osmAPI | ||
* @param {string} id | ||
* @returns {Promise} $http.delete response | ||
* DELETE /0.6/relation/#id | ||
*/ | ||
this.deleteRelation = function (id) { | ||
return this.delete('/0.6/relation/' + id); | ||
}; | ||
} | ||
@@ -553,3 +756,3 @@ | ||
var osmSettingsModule = angular.module('osm.settings', [ngStorageModuleName]).factory('osmSettingsService', _settings2.default); | ||
var osmSettingsModule = angular.module('osm.settings', [ngStorageModuleName]).service('osmSettingsService', _settings2.default); | ||
@@ -568,3 +771,2 @@ exports.default = osmSettingsModule; | ||
/** | ||
@@ -578,70 +780,39 @@ * @ngdoc service | ||
function osmSettingsService($localStorage) { | ||
return { | ||
localStorage: $localStorage.$default({ | ||
userName: '', | ||
userID: '', | ||
credentials: '', | ||
nodes: [], | ||
changeset: '', | ||
osmAPI: '', | ||
overpassAPI: '' | ||
}), | ||
getUserName: function getUserName() { | ||
return this.localStorage.userName; | ||
}, | ||
setUserName: function setUserName(username) { | ||
this.localStorage.userName = username; | ||
}, | ||
getUserID: function getUserID() { | ||
return this.localStorage.userID; | ||
}, | ||
setUserID: function setUserID(userid) { | ||
this.localStorage.userID = userid; | ||
}, | ||
getCredentials: function getCredentials() { | ||
return this.localStorage.credentials; | ||
}, | ||
setCredentials: function setCredentials(credentials) { | ||
this.localStorage.credentials = credentials; | ||
}, | ||
getOSMAPI: function getOSMAPI() { | ||
if (this.localStorage.osmAPI) { | ||
return this.localStorage.osmAPI; | ||
} else { | ||
return 'http://api.openstreetmap.org/api'; | ||
} | ||
}, | ||
setOSMAPI: function setOSMAPI(osmAPI) { | ||
this.localStorage.osmAPI = osmAPI; | ||
}, | ||
getOverpassAPI: function getOverpassAPI() { | ||
if (this.localStorage.overpassAPI) { | ||
return this.localStorage.overpassAPI; | ||
} else { | ||
//return 'http://api.openstreetmap.org/api'; | ||
return 'http://overpass-api.de/api/interpreter'; | ||
} | ||
}, | ||
setOverpassAPI: function setOverpassAPI(overpassAPI) { | ||
this.localStorage.overpassAPI = overpassAPI; | ||
}, | ||
getNodes: function getNodes() { | ||
return this.localStorage.nodes; | ||
}, | ||
setNodes: function setNodes(nodes) { | ||
this.localStorage.nodes = nodes; | ||
}, | ||
getChangeset: function getChangeset() { | ||
return this.localStorage.changeset; | ||
}, | ||
setChangeset: function setChangeset(changeset) { | ||
this.localStorage.changeset = changeset; | ||
}, | ||
getOsmAuth: function getOsmAuth() { | ||
return this.localStorage.osmAuth; | ||
}, | ||
setOsmAuth: function setOsmAuth(options) { | ||
return this.localStorage.osmAuth = options; | ||
} | ||
this.localStorage = $localStorage.$default({ | ||
userName: '', | ||
userID: '', | ||
credentials: '', | ||
changeset: '' | ||
}); | ||
this.getUserName = function () { | ||
return this.localStorage.userName; | ||
}; | ||
this.setUserName = function (username) { | ||
this.localStorage.userName = username; | ||
}; | ||
this.getUserID = function () { | ||
return this.localStorage.userID; | ||
}; | ||
this.setUserID = function (userid) { | ||
this.localStorage.userID = userid; | ||
}; | ||
this.getCredentials = function () { | ||
return this.localStorage.credentials; | ||
}; | ||
this.setCredentials = function (credentials) { | ||
this.localStorage.credentials = credentials; | ||
}; | ||
this.getChangeset = function () { | ||
return this.localStorage.changeset; | ||
}; | ||
this.setChangeset = function (changeset) { | ||
this.localStorage.changeset = changeset; | ||
}; | ||
this.getOsmAuth = function () { | ||
return this.localStorage.osmAuth; | ||
}; | ||
this.setOsmAuth = function (options) { | ||
this.localStorage.osmAuth = options; | ||
}; | ||
} | ||
@@ -675,5 +846,9 @@ | ||
var _x2js = __webpack_require__(9); | ||
var _x2js2 = _interopRequireDefault(_x2js); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var osmUtilsModule = angular.module('osm.utils', [_settings2.default.name]).service('osmUtilsService', _utils2.default); | ||
var osmUtilsModule = angular.module('osm.utils', [_settings2.default.name, _x2js2.default.name]).service('osmUtilsService', _utils2.default); | ||
@@ -695,116 +870,13 @@ exports.default = osmUtilsModule; | ||
*/ | ||
function osmUtilsService(osmSettingsService) { | ||
var _this = this; | ||
function osmUtilsService($http, osmSettingsService, osmx2js) { | ||
this.serializer = new XMLSerializer(); | ||
if (typeof window.DOMParser !== 'undefined') { | ||
(function () { | ||
var parser = new window.DOMParser(); | ||
_this.parseXml = function parseXml(xmlStr) { | ||
return parser.parseFromString(xmlStr, 'application/xml'); | ||
}; | ||
})(); | ||
} else if (typeof window.ActiveXObject !== 'undefined') { | ||
this.parseXml = function parseXml(xmlStr) { | ||
var xmlDoc = new window.ActiveXObject('Microsoft.XMLDOM'); | ||
xmlDoc.async = 'false'; | ||
xmlDoc.loadXML(xmlStr); | ||
return xmlDoc; | ||
}; | ||
} else { | ||
throw new Error('No XML parser found'); | ||
} | ||
/** | ||
* @ngdoc method | ||
* @name createNodeXML | ||
* @name relationToGeoJSON | ||
* @methodOf osm.utils.osmUtilsService | ||
* @param {Object} node geojson | ||
* @return {string} XML | ||
* <osm> | ||
<node changeset="12" lat="..." lon="..."> | ||
<tag k="note" v="Just a node"/> | ||
... | ||
</node> | ||
</osm> | ||
*/ | ||
this.createNodeXML = function (node) { | ||
var newNode = '<osm><node changeset="CHANGESET" lat="LAT" lon="LNG">TAGS</node></osm>'; | ||
var tagTPL = '<tag k="KEY" v="VALUE"/>'; | ||
var tags = ''; | ||
var value; | ||
newNode = newNode.replace('CHANGESET', osmSettingsService.getChangeset()); | ||
for (var property in node.tags) { | ||
if (node.tags.hasOwnProperty(property)) { | ||
value = node.tags[property]; | ||
if (value === undefined || value === null) { | ||
continue; | ||
} else { | ||
tags += tagTPL.replace('KEY', property).replace('VALUE', node.tags[property]); | ||
} | ||
} | ||
} | ||
newNode = newNode.replace('TAGS', tags); | ||
newNode = newNode.replace('LNG', node.lng); | ||
newNode = newNode.replace('LAT', node.lat); | ||
return newNode; | ||
}; | ||
/** | ||
* @ngdoc method | ||
* @name serialiseXmlToString | ||
* @methodOf osm.utils.osmUtilsService | ||
* @param {Object} xml document object | ||
* @return {string} XML | ||
*/ | ||
this.serialiseXmlToString = function (xml) { | ||
return this.serializer.serializeToString(xml); | ||
}; | ||
/** | ||
* @ngdoc method | ||
* @name getTagsFromChildren | ||
* @methodOf osm.utils.osmUtilsService | ||
* @param {Object} element document element object | ||
* @return {Object} tags {k1:v1,k2: v2} | ||
*/ | ||
this.getTagsFromChildren = function (element) { | ||
var children, tags; | ||
tags = {}; | ||
for (var i = 0; i < element.children.length; i++) { | ||
children = element.children[i]; | ||
if (children.tagName !== 'tag') { | ||
continue; | ||
} | ||
tags[children.getAttribute('k')] = children.getAttribute('v'); | ||
} | ||
return tags; | ||
}; | ||
/** | ||
* @ngdoc method | ||
* @name getNameFromTags | ||
* @methodOf osm.utils.osmUtilsService | ||
* @param {Object} element document element object | ||
* @return {string} name value | ||
*/ | ||
this.getNameFromTags = function (element) { | ||
var children; | ||
for (var i = 0; i < element.children.length; i++) { | ||
children = element.children[i]; | ||
if (children.tagName !== 'tag') { | ||
continue; | ||
} | ||
if (children.getAttribute('k') === 'name') { | ||
return children.getAttribute('v'); | ||
} | ||
} | ||
}; | ||
/** | ||
* @ngdoc method | ||
* @name relationXmlToGeoJSON | ||
* @methodOf osm.utils.osmUtilsService | ||
* @param {Number} relationId id of the relation | ||
* @param {Object} relationXML document element object | ||
* @param {Object} relation json object | ||
* @return {Object} geojson | ||
*/ | ||
this.relationXmlToGeoJSON = function (relationID, relationXML) { | ||
this.relationToGeoJSON = function (relationID, relation) { | ||
var self = this; | ||
@@ -1068,17 +1140,9 @@ var features = []; | ||
}; | ||
/** | ||
* @ngdoc method | ||
* @name getNodesInJSON | ||
* @methodOf osm.utils.osmUtilsService | ||
* @param {Object} relationGeoJSON geojson | ||
* @return {Object} relation as geojson sorted | ||
*/ | ||
this.getNodesInJSON = function (xmlNodes, flatProperties) { | ||
osmSettingsService.setNodes(xmlNodes); | ||
var options = {}; | ||
if (flatProperties !== undefined) { | ||
options.flatProperties = flatProperties; | ||
} | ||
return osmtogeojson(xmlNodes, options); | ||
this.x2js = osmx2js; | ||
this.xml2js = function (xml_str) { | ||
return osmx2js.xml2js(xml_str); | ||
}; | ||
this.js2xml = function (json) { | ||
return osmx2js.js2xml(json); | ||
}; | ||
/** | ||
@@ -1136,6 +1200,25 @@ * @ngdoc method | ||
module.exports = __WEBPACK_EXTERNAL_MODULE_9__; | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
//https://github.com/abdmob/x2js as angular service | ||
var osmx2jsModule = angular.module('osm.x2js', []).provider('osmx2js', function osmx2jsProvider() { | ||
this.options = {}; | ||
this.$get = function osmx2jsFactory() { | ||
return new X2JS(this.options); //X2JS must be global | ||
}; | ||
}); | ||
exports.default = osmx2jsModule; | ||
/***/ }, | ||
/* 10 */ | ||
/***/ function(module, exports) { | ||
module.exports = __WEBPACK_EXTERNAL_MODULE_10__; | ||
/***/ }, | ||
/* 11 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
@@ -1149,3 +1232,3 @@ | ||
var _oauth = __webpack_require__(11); | ||
var _oauth = __webpack_require__(12); | ||
@@ -1168,3 +1251,3 @@ var _oauth2 = _interopRequireDefault(_oauth); | ||
/***/ }, | ||
/* 11 */ | ||
/* 12 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
@@ -1178,3 +1261,3 @@ | ||
var _osmAuth = __webpack_require__(12); | ||
var _osmAuth = __webpack_require__(13); | ||
@@ -1197,8 +1280,25 @@ var _osmAuth2 = _interopRequireDefault(_osmAuth); | ||
} | ||
/** | ||
* @ngdoc method | ||
* @name logout | ||
* @methodOf osm.auth.osmAuthService | ||
*/ | ||
this.logout = function () { | ||
return this.auth.logout(); | ||
this.auth.logout(); | ||
}; | ||
/** | ||
* @ngdoc method | ||
* @name authenticated | ||
* @methodOf osm.auth.osmAuthService | ||
* @return {boolean} authenticated | ||
*/ | ||
this.authenticated = function () { | ||
return this.auth.authenticated(); | ||
}; | ||
/** | ||
* @ngdoc method | ||
* @name authenticate | ||
* @methodOf osm.auth.osmAuthService | ||
* @return {Promise} true/false | ||
*/ | ||
this.authenticate = function () { | ||
@@ -1211,2 +1311,8 @@ var deferred = $q.defer(); | ||
}; | ||
/** | ||
* @ngdoc method | ||
* @name xhr | ||
* @methodOf osm.auth.osmAuthService | ||
* @return {Promise} http response | ||
*/ | ||
this.xhr = function (options) { | ||
@@ -1223,2 +1329,7 @@ var deferred = $q.defer(); | ||
}; | ||
/** | ||
* @ngdoc method | ||
* @name options | ||
* @methodOf osm.auth.osmAuthService | ||
*/ | ||
this.options = function (options) { | ||
@@ -1236,9 +1347,9 @@ if (this.auth) { | ||
/***/ }, | ||
/* 12 */ | ||
/* 13 */ | ||
/***/ function(module, exports) { | ||
module.exports = __WEBPACK_EXTERNAL_MODULE_12__; | ||
module.exports = __WEBPACK_EXTERNAL_MODULE_13__; | ||
/***/ }, | ||
/* 13 */ | ||
/* 14 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
@@ -1249,6 +1360,6 @@ | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
value: true | ||
}); | ||
var _overpass = __webpack_require__(14); | ||
var _overpass = __webpack_require__(15); | ||
@@ -1263,3 +1374,11 @@ var _overpass2 = _interopRequireDefault(_overpass); | ||
var osmOverpassModule = angular.module('osm.overpass', [_settings2.default.name]).factory('osmOverpassAPI', _overpass2.default); | ||
var osmOverpassModule = angular.module('osm.overpass', [_settings2.default.name]).factory('osmOverpassAPI', _overpass2.default).provider('osmOverpassAPI', function osmOverpassAPIProvider() { | ||
this.options = { | ||
url: 'http://overpass-api.de/api/interpreter' | ||
}; | ||
this.$get = function osmOverpassAPIFactory($http, $q, osmSettingsService) { | ||
return new _overpass2.default($http, $q, osmSettingsService, this.options); | ||
}; | ||
this.$get.$inject = ['$http', '$q', 'osmSettingsService']; | ||
}); | ||
@@ -1269,3 +1388,3 @@ exports.default = osmOverpassModule; | ||
/***/ }, | ||
/* 14 */ | ||
/* 15 */ | ||
/***/ function(module, exports) { | ||
@@ -1287,92 +1406,121 @@ | ||
*/ | ||
osmOverpassAPI.$inject = ['$http', '$q', 'osmSettingsService']; | ||
function osmOverpassAPI($http, $q, osmSettingsService) { | ||
var service = { | ||
overpass: function overpass(query) { | ||
var url = osmSettingsService.getOverpassAPI(); | ||
var deferred = $q.defer(); | ||
var self = this; | ||
var headers = { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' }; | ||
$http.post(url, 'data=' + encodeURIComponent(query), { headers: headers }).then(function (data) { | ||
deferred.resolve(data.data); | ||
}, function (data) { | ||
deferred.reject(data); | ||
}); | ||
return deferred.promise; | ||
}, | ||
overpassToGeoJSON: function overpassToGeoJSON(query, filter) { | ||
var deferred = $q.defer(); | ||
var features = []; | ||
var relations = []; | ||
var result = { | ||
type: 'FeatureCollection', | ||
features: features, | ||
relations: relations | ||
function osmOverpassAPI($http, $q, osmSettingsService, options) { | ||
this.url = options.url; | ||
/** | ||
* @ngdoc method | ||
* @name overpass | ||
* @param {Object/String} query | ||
* http://wiki.openstreetmap.org/wiki/FR:Overpass_API | ||
* @methodOf osm.overpass.osmOverpassAPI | ||
* @return {Promise} $http.get | ||
*/ | ||
this.overpass = function (query) { | ||
var self = this; | ||
var url = self.url; | ||
var deferred = $q.defer(); | ||
var headers = { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' }; | ||
$http.post(url, 'data=' + encodeURIComponent(query), { headers: headers }).then(function (data) { | ||
deferred.resolve(data.data); | ||
}, function (data) { | ||
deferred.reject(data); | ||
}); | ||
return deferred.promise; | ||
}; | ||
/** | ||
* @ngdoc method | ||
* @name overpass | ||
* @description | ||
* http://wiki.openstreetmap.org/wiki/FR:Overpass_API/Overpass_QL#By_area_.28area.29 | ||
By convention the area id can be calculated from an existing OSM way by adding 2400000000 to its OSM id, or in case of a relation by adding 3600000000 respectively. Note that area creation is subject to some extraction rules, i.e. not all ways/relations have an area counterpart (notably those that are tagged with area=no, and most multipolygons and that don't have a defined name=* will not be part of areas). | ||
* @param {String} type 'r'/'relation' or 'w'/'way' | ||
* @param {String/Number} osmId the id of the element | ||
* @methodOf osm.overpass.osmOverpassAPI | ||
* @return {Number} the area id | ||
*/ | ||
this.getAreaId = function (type, osmId) { | ||
var id; | ||
if (typeof osmId === 'string') { | ||
id = parseInt(osmId, 10); | ||
} else { | ||
id = osmId; | ||
} | ||
if (type === 'r' || type === 'relation') { | ||
return 3600000000 + id; | ||
} else if (type === 'w' || type === 'way') { | ||
return 2400000000 + id; | ||
} | ||
}; | ||
this.overpassToGeoJSON = function (query, filter) { | ||
var deferred = $q.defer(); | ||
var features = []; | ||
var relations = []; | ||
var result = { | ||
type: 'FeatureCollection', | ||
features: features, | ||
relations: relations | ||
}; | ||
if (filter === undefined) { | ||
filter = function filter() {}; | ||
} | ||
this.overpass(query).then(function (data) { | ||
//TODO check if data is XML or JSON, here it's JSON | ||
var node, feature, coordinates; | ||
var cache = { loaded: false }; | ||
function getNodeById(id) { | ||
if (!cache.loaded) { | ||
var tmp; | ||
for (var i = 0; i < data.elements.length; i++) { | ||
tmp = data.elements[i]; | ||
cache[tmp.id] = tmp; | ||
} | ||
} | ||
return cache[id]; | ||
}; | ||
if (filter === undefined) { | ||
filter = function filter() {}; | ||
} | ||
this.overpass(query).then(function (data) { | ||
//TODO check if data is XML or JSON, here it's JSON | ||
var node, feature, coordinates; | ||
var cache = { loaded: false }; | ||
function getNodeById(id) { | ||
if (!cache.loaded) { | ||
var tmp; | ||
for (var i = 0; i < data.elements.length; i++) { | ||
tmp = data.elements[i]; | ||
cache[tmp.id] = tmp; | ||
for (var i = 0; i < data.elements.length; i++) { | ||
node = data.elements[i]; | ||
if (node.type === 'node') { | ||
feature = { | ||
type: 'Feature', | ||
properties: node.tags, | ||
id: node.id, | ||
geometry: { | ||
type: 'Point', | ||
coordinates: [node.lon, node.lat] | ||
} | ||
}; | ||
if (!filter(feature)) { | ||
features.push(feature); | ||
} | ||
return cache[id]; | ||
}; | ||
for (var i = 0; i < data.elements.length; i++) { | ||
node = data.elements[i]; | ||
if (node.type === 'node') { | ||
feature = { | ||
type: 'Feature', | ||
properties: node.tags, | ||
id: node.id, | ||
geometry: { | ||
type: 'Point', | ||
coordinates: [node.lon, node.lat] | ||
} | ||
}; | ||
if (!filter(feature)) { | ||
features.push(feature); | ||
} else if (node.type === 'way') { | ||
coordinates = []; | ||
feature = { | ||
type: 'Feature', | ||
properties: node.tags, | ||
id: node.id, | ||
geometry: { | ||
type: 'LineString', | ||
coordinates: coordinates | ||
} | ||
} else if (node.type === 'way') { | ||
coordinates = []; | ||
feature = { | ||
type: 'Feature', | ||
properties: node.tags, | ||
id: node.id, | ||
geometry: { | ||
type: 'LineString', | ||
coordinates: coordinates | ||
} | ||
}; | ||
for (var j = 0; j < node.nodes.length; j++) { | ||
coordinates.push([getNodeById(node.nodes[j]).lon, getNodeById(node.nodes[j]).lat]); | ||
} | ||
if (!filter(feature)) { | ||
features.push(feature); | ||
} | ||
} else if (node.type === 'relation') { | ||
result.relations.push({ | ||
ref: node.id, | ||
tags: node.tags, | ||
type: 'relation', | ||
members: node.members | ||
}); | ||
}; | ||
for (var j = 0; j < node.nodes.length; j++) { | ||
coordinates.push([getNodeById(node.nodes[j]).lon, getNodeById(node.nodes[j]).lat]); | ||
} | ||
if (!filter(feature)) { | ||
features.push(feature); | ||
} | ||
} else if (node.type === 'relation') { | ||
result.relations.push({ | ||
ref: node.id, | ||
tags: node.tags, | ||
type: 'relation', | ||
members: node.members | ||
}); | ||
} | ||
deferred.resolve(result); | ||
}, function (error) { | ||
deferred.reject(error); | ||
}); | ||
return deferred.promise; | ||
} | ||
} | ||
deferred.resolve(result); | ||
}, function (error) { | ||
deferred.reject(error); | ||
}); | ||
return deferred.promise; | ||
}; | ||
return service; | ||
} | ||
@@ -1383,3 +1531,3 @@ | ||
/***/ }, | ||
/* 15 */ | ||
/* 16 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
@@ -1393,3 +1541,3 @@ | ||
var _taginfo = __webpack_require__(16); | ||
var _taginfo = __webpack_require__(17); | ||
@@ -1405,3 +1553,3 @@ var _taginfo2 = _interopRequireDefault(_taginfo); | ||
/***/ }, | ||
/* 16 */ | ||
/* 17 */ | ||
/***/ function(module, exports) { | ||
@@ -1709,2 +1857,137 @@ | ||
/***/ }, | ||
/* 18 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var _nominatim = __webpack_require__(19); | ||
var _nominatim2 = _interopRequireDefault(_nominatim); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var osmNominatimModule = angular.module('osm.nominatim', []).factory('osmNominatim', _nominatim2.default).provider('osmNominatim', function osmNominatimProvider() { | ||
this.options = { | ||
url: 'https://nominatim.openstreetmap.org' | ||
}; | ||
this.$get = function osmNominatimFactory($q) { | ||
return new _nominatim2.default($q, this.options); | ||
}; | ||
this.$get.$inject = ['$http']; | ||
}); | ||
exports.default = osmNominatimModule; | ||
/***/ }, | ||
/* 19 */ | ||
/***/ function(module, exports) { | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
/** | ||
* @ngdoc service | ||
* @name osm.nominatim.osmNominatim | ||
* @description handle nominatim query | ||
*/ | ||
function osmNominatim($http, options) { | ||
this.url = options.url; | ||
/** | ||
* @ngdoc method | ||
* @name search | ||
* @param {Object/String} query | ||
* http://wiki.openstreetmap.org/wiki/Nominatim | ||
* @methodOf osm.nominatim.osmNominatim | ||
* @return {Promise} $http.get | ||
*/ | ||
this.search = function search(query) { | ||
//https://nominatim.openstreetmap.org/search | ||
//?X-Requested-With=overpass-turbo&format=json&q=vern-sur-seiche | ||
//params['accept-language'] = 'fr'; | ||
var params; | ||
if (typeof query === 'string' || !query) { | ||
params = { | ||
format: 'json', | ||
q: query | ||
}; | ||
} else { | ||
params = angular.copy(query); | ||
params.format = 'json'; | ||
} | ||
var config = { | ||
params: params | ||
}; | ||
var url = this.url + '/search'; | ||
return $http.get(url, config); | ||
}; | ||
/** | ||
* @ngdoc method | ||
* @name reverse | ||
* @param {Object/String} query | ||
* http://wiki.openstreetmap.org/wiki/Nominatim | ||
* @methodOf osm.nominatim.osmNominatim | ||
* @return {Promise} $http.get | ||
*/ | ||
this.reverse = function reverse(query) { | ||
//https://nominatim.openstreetmap.org/reverse | ||
//?X-Requested-With=overpass-turbo&format=json&q=vern-sur-seiche | ||
//params['accept-language'] = 'fr'; | ||
var params; | ||
if (typeof query === 'string') { | ||
params = { | ||
format: 'json', | ||
q: query | ||
}; | ||
} else { | ||
params = angular.copy(query); | ||
params.format = 'json'; | ||
} | ||
var config = { | ||
params: params | ||
}; | ||
var url = this.url + '/reverse'; | ||
return $http.get(url, config); | ||
}; | ||
/** | ||
* @ngdoc method | ||
* @name lookup | ||
* @description | ||
* http://nominatim.openstreetmap.org/lookup?osm_ids=R146656,W104393803,N240109189 | ||
* @param {Object/String} query | ||
* http://wiki.openstreetmap.org/wiki/Nominatim | ||
* @methodOf osm.nominatim.osmNominatim | ||
* @return {Promise} $http.get | ||
*/ | ||
this.lookup = function lookup(query) { | ||
var params; | ||
if (typeof query === 'string') { | ||
params = { | ||
format: 'json', | ||
q: query | ||
}; | ||
} else { | ||
params = angular.copy(query); | ||
params.format = 'json'; | ||
} | ||
var config = { | ||
params: params | ||
}; | ||
var url = this.url + '/lookup'; | ||
return $http.get(url, config); | ||
}; | ||
} | ||
exports.default = osmNominatim; | ||
/***/ } | ||
@@ -1711,0 +1994,0 @@ /******/ ]) |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("angular-base64"),require("ngstorage"),require("angular"),require("osm-auth")):"function"==typeof define&&define.amd?define(["angular-base64","ngstorage","angular","osm-auth"],t):"object"==typeof exports?exports.name=t(require("angular-base64"),require("ngstorage"),require("angular"),require("osm-auth")):(e["angular-osm"]=e["angular-osm"]||{},e["angular-osm"].name=t(e["angular-base64"],e.ngstorage,e.angular,e["osm-auth"]))}(this,function(e,t,r,n){return function(e){function t(n){if(r[n])return r[n].exports;var i=r[n]={exports:{},id:n,loaded:!1};return e[n].call(i.exports,i,i.exports,t),i.loaded=!0,i.exports}var r={};return t.m=e,t.c=r,t.p="",t(0)}([function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{"default":e}}var i=r(9),o=n(i),s=r(10),a=n(s),u=r(1),l=n(u),c=r(13),g=n(c),f=r(15),h=n(f),d=r(4),p=n(d);o["default"].module("osm",[p["default"].name,l["default"].name,g["default"].name,h["default"].name,a["default"].name])},function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{"default":e}}Object.defineProperty(t,"__esModule",{value:!0});var i=r(2),o=(n(i),r(3)),s=n(o),a=r(4),u=n(a),l=r(7),c=n(l),g=angular.module("osm.api",[u["default"].name,c["default"].name,"base64"]).service("osmAPI",s["default"]);t["default"]=g},function(t,r){t.exports=e},function(e,t){"use strict";function r(e,t,r,i,o){this.validateCredentials=function(){var e=r.defer();return this.getUserDetails().then(function(t){var r=o.parseXml(t),n=r.getElementsByTagName("user");1===n.length&&i.setUserID(n[0].id),e.resolve(n.length>0)},function(t){e.reject(t)}),e.promise},this.setCredentials=function(t,r){i.setUserName(t);var n=e.encode(t+":"+r);return i.setCredentials(n),n},this.getCredentials=function(){return i.getCredentials()},this.getAuthorization=function(){return"Basic "+i.getCredentials()},this.clearCredentials=function(){i.setCredentials("")},this.getAuthenticated=function(e,t){return void 0===t&&(t={}),t.headers={Authorization:this.getAuthorization()},this.get(e,t)},this.get=function(e,n){var o=r.defer(),s=i.getOSMAPI()+e;return t.get(s,n).then(function(e){o.resolve(e.data)},function(e){o.reject(e)}),o.promise},this.put=function(e,n,o){var s=r.defer();void 0===o&&(o={}),o.headers={Authorization:this.getAuthorization()};var a=i.getOSMAPI()+e;return t.put(a,n,o).then(function(e){s.resolve(e.data)},function(e){s.reject(e)}),s.promise},this["delete"]=function(e,n){var o=r.defer();return void 0===n&&(n={}),n.headers={Authorization:this.getAuthorization()},n.url=i.getOSMAPI()+e,n.method="delete",t(n).then(function(e){o.resolve(e.data)},function(e){o.reject(e)}),o.promise},this.createChangeset=function(e){var t=r.defer(),n='<osm><changeset><tag k="created_by" v="Angular-OSM"/><tag k="comment" v="';return n+=e+'"/></changeset></osm>',this.put("/0.6/changeset/create",n).then(function(e){i.setChangeset(e),t.resolve(e)}),t.promise},this.getLastOpenedChangesetId=function(){var e=r.defer(),t={params:{user:i.getUserID(),open:!0}};return this.get("/0.6/changesets",t).then(function(t){var r=o.parseXml(t),n=r.getElementsByTagName("changeset");n.length>0?(i.setChangeset(n[0].id),e.resolve(n[0].id)):(i.setChangeset(),e.resolve())}),e.promise},this.closeChangeset=function(){var e=i.getChangeset();return this.put("/0.6/changeset/"+e+"/close").then(function(e){return i.setChangeset(),e})},this.getUserDetails=function(){return this.getAuthenticated("/0.6/user/details")},this.getMap=function(e){return this.get("/0.6/map?bbox="+e)},this.getNotes=function(e,t){var r="/0.6/notes";return t&&(r+="."+t),r+="?bbox="+e,this.get(r)},this.updateNode=function(e,t){var n=i.getNodes(),o=n.getElementById(e.properties.id),s=r.defer();if(null===o)return s.reject({msg:"can t find node",currentNode:e,updatedNode:t,osmNode:o}),s.promise;var a;for(o.setAttribute("changeset",i.getChangeset()),o.setAttribute("user",i.getUserName());o.getElementsByTagName("tag")[0];)o.removeChild(o.getElementsByTagName("tag")[0]);var u,l=document.createElement("osm");l.appendChild(o);for(var c in t.properties.tags)if(t.properties.tags.hasOwnProperty(c)){if(u=t.properties.tags[c],void 0===u)continue;a=document.createElement("tag"),a.setAttribute("k",c),a.setAttribute("v",u),o.appendChild(a)}var g;if("Polygon"===t.geometry.type)g="way";else if("Point"===t.geometry.type)g="node";else{if("LineString"!==t.geometry.type)return s.reject({msg:"geojson type not supported",currentNode:e,updatedNode:t,osmNode:o}),s.promise;g="way"}var f="/0.6/"+g+"/"+e.properties.id;return this.put(f,l.outerHTML)},this.createNode=function(e){var t=e;return"object"===("undefined"==typeof e?"undefined":n(e))&&(t=o.createNodeXML(e)),this.put("/0.6/node/create",t)},this.getMapGeoJSON=function(e){var t=this,n=r.defer();return t.getMap(e).then(function(e){var t=o.parseXml(e),r=o.getNodesInJSON(t);n.resolve(r)},function(e){n.reject(e)}),n.promise}}Object.defineProperty(t,"__esModule",{value:!0});var n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol?"symbol":typeof e};r.$inject=["$base64","$http","$q","osmSettingsService","osmUtilsService"],t["default"]=r},function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{"default":e}}Object.defineProperty(t,"__esModule",{value:!0});var i=r(5),o=n(i),s=r(6),a=n(s),u=a["default"]?a["default"].name:"ngStorage",l=angular.module("osm.settings",[u]).factory("osmSettingsService",o["default"]);t["default"]=l},function(e,t){"use strict";function r(e){return{localStorage:e.$default({userName:"",userID:"",credentials:"",nodes:[],changeset:"",osmAPI:"",overpassAPI:""}),getUserName:function(){return this.localStorage.userName},setUserName:function(e){this.localStorage.userName=e},getUserID:function(){return this.localStorage.userID},setUserID:function(e){this.localStorage.userID=e},getCredentials:function(){return this.localStorage.credentials},setCredentials:function(e){this.localStorage.credentials=e},getOSMAPI:function(){return this.localStorage.osmAPI?this.localStorage.osmAPI:"http://api.openstreetmap.org/api"},setOSMAPI:function(e){this.localStorage.osmAPI=e},getOverpassAPI:function(){return this.localStorage.overpassAPI?this.localStorage.overpassAPI:"http://overpass-api.de/api/interpreter"},setOverpassAPI:function(e){this.localStorage.overpassAPI=e},getNodes:function(){return this.localStorage.nodes},setNodes:function(e){this.localStorage.nodes=e},getChangeset:function(){return this.localStorage.changeset},setChangeset:function(e){this.localStorage.changeset=e},getOsmAuth:function(){return this.localStorage.osmAuth},setOsmAuth:function(e){return this.localStorage.osmAuth=e}}}Object.defineProperty(t,"__esModule",{value:!0}),r.$inject=["$localStorage"],t["default"]=r},function(e,r){e.exports=t},function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{"default":e}}Object.defineProperty(t,"__esModule",{value:!0});var i=r(8),o=n(i),s=r(4),a=n(s),u=angular.module("osm.utils",[a["default"].name]).service("osmUtilsService",o["default"]);t["default"]=u},function(e,t){"use strict";function r(e){var t=this;if(this.serializer=new XMLSerializer,"undefined"!=typeof window.DOMParser)!function(){var e=new window.DOMParser;t.parseXml=function(t){return e.parseFromString(t,"application/xml")}}();else{if("undefined"==typeof window.ActiveXObject)throw new Error("No XML parser found");this.parseXml=function(e){var t=new window.ActiveXObject("Microsoft.XMLDOM");return t.async="false",t.loadXML(e),t}}this.createNodeXML=function(t){var r,n='<osm><node changeset="CHANGESET" lat="LAT" lon="LNG">TAGS</node></osm>',i='<tag k="KEY" v="VALUE"/>',o="";n=n.replace("CHANGESET",e.getChangeset());for(var s in t.tags)if(t.tags.hasOwnProperty(s)){if(r=t.tags[s],void 0===r||null===r)continue;o+=i.replace("KEY",s).replace("VALUE",t.tags[s])}return n=n.replace("TAGS",o),n=n.replace("LNG",t.lng),n=n.replace("LAT",t.lat)},this.serialiseXmlToString=function(e){return this.serializer.serializeToString(e)},this.getTagsFromChildren=function(e){var t,r;r={};for(var n=0;n<e.children.length;n++)t=e.children[n],"tag"===t.tagName&&(r[t.getAttribute("k")]=t.getAttribute("v"));return r},this.getNameFromTags=function(e){for(var t,r=0;r<e.children.length;r++)if(t=e.children[r],"tag"===t.tagName&&"name"===t.getAttribute("k"))return t.getAttribute("v")},this.relationXmlToGeoJSON=function(e,t){var r=this,n=[],i=[],o={type:"FeatureCollection",properties:{id:e},options:{},members:[],features:n,relations:i},s=t.getElementById(e);o.properties.visible=s.getAttribute("visible"),o.properties.version=s.getAttribute("version"),o.properties.changeset=s.getAttribute("changeset"),o.properties.timestamp=s.getAttribute("timestamp"),o.properties.user=s.getAttribute("user"),o.properties.uid=s.getAttribute("uid");var a,u,l,c,g,f,h,d,p;for(u=0;u<s.children.length;u++)if(a=s.children[u],"member"===a.tagName)if(d={type:a.getAttribute("type"),ref:a.getAttribute("ref"),role:a.getAttribute("role")},o.members.push(d),p=t.getElementById(a.getAttribute("ref")),g=r.getTagsFromChildren(p),d.name=g.name,"way"===p.tagName){f=[],h={type:"Feature",properties:g,id:a.getAttribute("ref"),geometry:{type:"LineString",coordinates:f}};for(var m=0;m<p.children.length;m++)l=p.children[m],"nd"===l.tagName&&(c=t.getElementById(l.getAttribute("ref")),f.push([parseFloat(c.getAttribute("lon")),parseFloat(c.getAttribute("lat"))]));n.push(h)}else"node"===p.tagName?(h={type:"Feature",properties:g,id:a.getAttribute("ref"),geometry:{type:"Point",coordinates:[parseFloat(p.getAttribute("lon")),parseFloat(p.getAttribute("lat"))]}},n.push(h)):"relation"===p.tagName&&(d.tags=g);return o.tags=r.getTagsFromChildren(s),o},this.encodeXML=function(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")},this.relationGeoJSONToXml=function(t){var r,n=t.properties,i=t.members,o=e,s='<?xml version="1.0" encoding="UTF-8"?>\n';for(s+='<osm version="0.6" generator="angular-osm 0.2" copyright="OpenStreetMap and contributors" attribution="http://www.openstreetmap.org/copyright" license="http://opendatacommons.org/licenses/odbl/1-0/">\n',s+=' <relation id="'+n.id+'" visible="'+n.visible+'" ',s+='version="'+n.version+'" ',s+='changeset="'+o.getChangeset()+'" timestamp="'+(new Date).toISOString()+'" ',s+='user="'+o.getUserName()+'" uid="'+n.uid+'">\n',r=0;r<i.length;r++)s+=' <member type="'+i[r].type+'" ',s+='ref="'+i[r].ref,s+="relation"===i[r].type?'" role="'+i[r].role+'"/>\n':'" role="'+i[r].role+'"/>\n';var a=t.tags;for(var u in a)s+=' <tag k="'+u+'" v="'+this.encodeXML(a[u])+'"/>\n';return s+=" </relation>\n",s+="</osm>"},this.sortRelationMembers=function(e){var t,r,n,i,o,s,a,u,l,c,g,f,h=e.members,d=e.features,p=[],m=function(e){p.splice(0,0,e)},v=function(e){p.push(e)},y=function(e){return d[e].geometry.coordinates},b=!1;for(r=0;r<h.length;r++)if(n=h[r],"way"===n.type){for(g=!1,o=0;o<p.length;o++)p[o].ref===n.ref&&(g=!0);if(!g){for(0===p.length&&(p.push(n),u=y(r),l=u[0],c=u[u.length-1]),f=b=!1,i=0;i<d.length;i++)if(t=d[i],"LineString"===t.geometry.type){for(g=!1,o=0;o<p.length;o++)p[o].ref===t.id&&(g=!0);g||(u=y(i),s=u[0],a=u[u.length-1],l[0]!==a[0]||l[1]!==a[1]?c[0]!==s[0]||c[1]!==s[1]?l[0]!==s[0]||l[1]!==s[1]?c[0]!==a[0]||c[1]!==a[1]||(v(h[i]),c=s,b=!0):(m(h[i]),l=a,f=!0):(v(h[i]),c=a,b=!0):(m(h[i]),l=s,f=!0))}f||b||(console.log("not found connected ways for "+n.ref),console.log(l),console.log(c))}}else p.push(n);if(h.length===p.length){e.members=p;var A={loaded:!1},S=function(e){if(!A.loaded)for(var t=0;t<d.length;t++)A[d[t].id]=d[t];return A[e]};e.features=[];for(var _=0;_<p.length;_++)e.features.push(S(p[_].ref))}else console.error("can t sort this relation");return e},this.getNodesInJSON=function(t,r){e.setNodes(t);var n={};return void 0!==r&&(n.flatProperties=r),osmtogeojson(t,n)},this.yqlJSON=function(e){var t,r,n=$q.defer();return r={params:{q:"select * from json where url='"+e+"';",format:"json"}},t="http://query.yahooapis.com/v1/public/yql",$http.get(t,r).then(function(e){null===e.data.query.results?n.resolve([]):n.resolve(e.data.query.results.json)},function(e){n.reject(e)}),n.promise},this.getElementTypeFromFeature=function(e){var t=e.geometry.type;return"LineString"===t?"way":"Point"===t?"node":void console.error("not supported type "+t)}}Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=r},function(e,t){e.exports=r},function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{"default":e}}Object.defineProperty(t,"__esModule",{value:!0});var i=r(11),o=n(i),s=angular.module("osm.oauth",[]).factory("osmAuthService",o["default"]).provider("osmAuthService",function(){this.options={},this.$get=function(e){return new o["default"](e,this.options)},this.$get.$inject=["$q"]});t["default"]=s},function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{"default":e}}function i(e,t){t&&t.oauth_secret&&t.oauth_consumer_key&&(this.auth=osmAuth(t)),this.logout=function(){return this.auth.logout()},this.authenticated=function(){return this.auth.authenticated()},this.authenticate=function(){var t=e.defer();return this.auth.authenticate(function(){t.resolve(!0)}),t.promise},this.xhr=function(t){var r=e.defer();return this.auth.xhr(t,function(e,t){e?r.reject(e):r.resolve(t)}),r.promise},this.options=function(e){this.auth?this.auth.options(e):this.auth=osmAuth(e)}}Object.defineProperty(t,"__esModule",{value:!0});var o=r(12);n(o);t["default"]=i},function(e,t){e.exports=n},function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{"default":e}}Object.defineProperty(t,"__esModule",{value:!0});var i=r(14),o=n(i),s=r(4),a=n(s),u=angular.module("osm.overpass",[a["default"].name]).factory("osmOverpassAPI",o["default"]);t["default"]=u},function(e,t){"use strict";function r(e,t,r){var n={overpass:function(n){var i=r.getOverpassAPI(),o=t.defer(),s={"Content-Type":"application/x-www-form-urlencoded; charset=UTF-8"};return e.post(i,"data="+encodeURIComponent(n),{headers:s}).then(function(e){o.resolve(e.data)},function(e){o.reject(e)}),o.promise},overpassToGeoJSON:function(e,r){var n=t.defer(),i=[],o=[],s={type:"FeatureCollection",features:i,relations:o};return void 0===r&&(r=function(){}),this.overpass(e).then(function(e){function t(t){if(!l.loaded)for(var r,n=0;n<e.elements.length;n++)r=e.elements[n],l[r.id]=r;return l[t]}for(var o,a,u,l={loaded:!1},c=0;c<e.elements.length;c++)if(o=e.elements[c],"node"===o.type)a={type:"Feature",properties:o.tags,id:o.id,geometry:{type:"Point",coordinates:[o.lon,o.lat]}},r(a)||i.push(a);else if("way"===o.type){u=[],a={type:"Feature",properties:o.tags,id:o.id,geometry:{type:"LineString",coordinates:u}};for(var g=0;g<o.nodes.length;g++)u.push([t(o.nodes[g]).lon,t(o.nodes[g]).lat]);r(a)||i.push(a)}else"relation"===o.type&&s.relations.push({ref:o.id,tags:o.tags,type:"relation",members:o.members});n.resolve(s)},function(e){n.reject(e)}),n.promise}};return n}Object.defineProperty(t,"__esModule",{value:!0}),r.$inject=["$http","$q","osmSettingsService"],t["default"]=r},function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{"default":e}}Object.defineProperty(t,"__esModule",{value:!0});var i=r(16),o=n(i),s=angular.module("osm.taginfo",[]).service("osmTagInfoAPI",o["default"]);t["default"]=s},function(e,t){"use strict";function r(e,t){this.get=function(r,n){var i=t.defer();return e.get("https://taginfo.openstreetmap.org/api/4"+r,n).then(function(e){i.resolve(e.data)},function(e){i.reject(e)}),i.promise},this.getKeyCombinations=function(e){return this.get("/key/combinations",{params:e})},this.getKeyDistributionNodes=function(e){return this.get("/key/distribution/nodes",{params:e})},this.getKeyDistributionWays=function(e){return this.get("/key/distribution/ways",{params:e})},this.getKeyStats=function(e){return this.get("/key/stats",{params:e})},this.getKeyValues=function(e){return this.get("/key/values",{params:e})},this.getKeyWikiPages=function(e){return this.get("/key/wiki_pages",{params:e})},this.getKeysAll=function(e){return this.get("/keys/all",{params:e})},this.getKeysWikiPages=function(e){return this.get("/keys/wiki_pages",{params:e})},this.getKeysWithoutWikiPage=function(e){return this.get("/keys/without_wiki_page",{params:e})},this.getRelationRoles=function(e){return this.get("/relation/roles",{params:e})},this.getRelationStats=function(e){return this.get("/relation/stats",{params:e})},this.getRelationWikiPages=function(e){return this.get("/relation/wiki_pages",{params:e})},this.getRelationsAll=function(e){return this.get("/relations/all",{params:e})},this.getSearchByKeyAndValue=function(e){return this.get("/search/by_key_and_value",{params:e})},this.getSearchByKeyword=function(e){return this.get("/search/by_keyword",{params:e})},this.getSearchByRole=function(e){return this.get("/search/by_role",{params:e})},this.getSearchByValue=function(e){return this.get("/search/by_value",{params:e})},this.getSiteInfo=function(e){return this.get("/site/info",{params:e})},this.getSiteSources=function(e){return this.get("/site/sources",{params:e})},this.getTagCombinations=function(e){return this.get("/tag/combinations",{params:e})},this.getTagDistributionNodes=function(e){return this.get("/tag/distribution/nodes",{params:e})},this.getTagDistributionWays=function(e){return this.get("/tag/distribution/ways",{params:e})},this.getTagStats=function(e){return this.get("/tag/stats",{params:e})},this.getTagWikiPages=function(e){return this.get("/tag/wiki_pages",{params:e})},this.getTagsPopular=function(e){return this.get("/tags/popular",{params:e})},this.getWikiLanguages=function(e){return this.get("/wiki/languages",{params:e})}}Object.defineProperty(t,"__esModule",{value:!0}),r.$inject=["$http","$q"],t["default"]=r}])}); | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("angular-base64"),require("ngstorage"),require("angular"),require("osm-auth")):"function"==typeof define&&define.amd?define(["angular-base64","ngstorage","angular","osm-auth"],t):"object"==typeof exports?exports.name=t(require("angular-base64"),require("ngstorage"),require("angular"),require("osm-auth")):(e["angular-osm"]=e["angular-osm"]||{},e["angular-osm"].name=t(e["angular-base64"],e.ngstorage,e.angular,e["osm-auth"]))}(this,function(e,t,r,n){return function(e){function t(n){if(r[n])return r[n].exports;var i=r[n]={exports:{},id:n,loaded:!1};return e[n].call(i.exports,i,i.exports,t),i.loaded=!0,i.exports}var r={};return t.m=e,t.c=r,t.p="",t(0)}([function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{"default":e}}var i=r(10),s=n(i),o=r(11),a=n(o),u=r(1),l=n(u),c=r(14),h=n(c),f=r(16),g=n(f),d=r(4),p=n(d),m=r(18),y=n(m);s["default"].module("osm",[p["default"].name,l["default"].name,h["default"].name,g["default"].name,a["default"].name,y["default"].name])},function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{"default":e}}Object.defineProperty(t,"__esModule",{value:!0});var i=r(2),s=(n(i),r(3)),o=n(s),a=r(4),u=n(a),l=r(7),c=n(l),h=angular.module("osm.api",[u["default"].name,c["default"].name,"base64"]).service("osmAPI",o["default"]).provider("osmAPI",function(){this.options={url:"http://api.openstreetmap.org/api"},this.$get=function(e,t,r,n,i){return new o["default"](e,t,r,n,i,this.options)},this.$get.$inject=["$base64","$http","$q","osmSettingsService","osmUtilsService"]});t["default"]=h},function(t,r){t.exports=e},function(e,t){"use strict";function r(e,t,r,i,s,o){function a(e){try{return e instanceof HTMLElement}catch(t){return"object"===("undefined"==typeof e?"undefined":n(e))&&1===e.nodeType&&"object"===n(e.style)&&"object"===n(e.ownerDocument)}}this.url=o.url,this.validateCredentials=function(){var e=r.defer();return this.getUserDetails().then(function(t){t.osm.user&&i.setUserID(t.osm.user._id),e.resolve(void 0!==t.osm.user)},function(t){e.reject(t)}),e.promise},this.setCredentials=function(t,r){i.setUserName(t);var n=e.encode(t+":"+r);return i.setCredentials(n),n},this.getCredentials=function(){return i.getCredentials()},this.getAuthorization=function(){return"Basic "+i.getCredentials()},this.clearCredentials=function(){i.setCredentials("")},this.setOauth=function(e){this._oauth=e},this.getOauth=function(){return this._oauth},this.xhr=function(e){var n=r.defer(),i=void 0,o=this._oauth;return o?(e.path="/api"+e.path,e.data&&(e.body=e.data,e.data=void 0),i=this._oauth.xhr(e)):(e.url=this.url+e.path,e.headers={Authorization:this.getAuthorization()},i=t(e)),i.then(function(e){var t,r=function(e){if(!e)return e;if(e.substr){if("<?xml"===e.substr(0,5))return s.xml2js(e)}else if(a(e))return s.x2js.dom2js(e);return e};t=o?e:e.data,n.resolve(r(t))},function(e){n.reject(e)}),n.promise},this.getAuthenticated=function(e,t){var r=angular.copy(t);return r||(r={}),r.method="GET",r.path=e,this.xhr(r)},this.get=function(e,n){var i=r.defer(),o=this.url+e;return t.get(o,n).then(function(e){i.resolve(s.xml2js(e.data))},function(e){i.reject(e)}),i.promise},this.put=function(e,t,r){r||(r={});var n=angular.copy(r);return n.method="PUT",n.path=e,n.data=s.js2xml(t),this.xhr(n)},this["delete"]=function(e,t){t||(t={});var r=angular.copy(t);return r.method="DELETE",r.path=e,this.xhr(r)},this.createChangeset=function(e){var t=r.defer(),n={osm:{changeset:{tag:[{_k:"created_by",_v:"Angular-OSM"},{_k:"comment",_v:e}]}}};return this.put("/0.6/changeset/create",n).then(function(e){i.setChangeset(e),t.resolve(e)}),t.promise},this.getLastOpenedChangesetId=function(){var e=r.defer(),t={params:{user:i.getUserID(),open:!0}};return this.get("/0.6/changesets",t).then(function(t){var r=t.osm.changeset;r.length>0?(i.setChangeset(r[0].id),e.resolve(r[0].id)):r._id?(i.setChangeset(r._id),e.resolve(r._id)):(i.setChangeset(),e.resolve())}),e.promise},this.closeChangeset=function(){var e=i.getChangeset();return this.put("/0.6/changeset/"+e+"/close").then(function(e){return i.setChangeset(),e})},this.getUserById=function(e){return this.getAuthenticated("/0.6/user/"+e)},this.getUserDetails=function(){return this.getAuthenticated("/0.6/user/details")},this.getUserPreferences=function(){return this.getAuthenticated("/0.6/user/preferences")},this.putUserPreferences=function(e,t){return this.put("/0.6/user/preferences/"+e,t)},this.getMap=function(e){return this.get("/0.6/map?bbox="+e)},this.getMapGeoJSON=function(e){var t=this,n=r.defer();return t.getMap(e).then(function(e){var t=s.js2geojson(e);n.resolve(t)},function(e){n.reject(e)}),n.promise},this.getNotes=function(e){var t="/0.6/notes?bbox="+e;return this.get(t)},this.createNode=function(e){return this.put("/0.6/node/create",e)},this.getNode=function(e){return this.get("/0.6/node/"+e)},this.deleteNode=function(e){return this["delete"]("/0.6/node/"+e)},this.createWay=function(e){return this.put("/0.6/way/create",e)},this.getWay=function(e){return this.get("/0.6/way/"+e)},this.deleteWay=function(e){return this["delete"]("/0.6/way/"+e)},this.createRelation=function(e){return this.put("/0.6/relation/create",e)},this.getRelation=function(e){return this.get("/0.6/relation/"+e)},this.deleteRelation=function(e){return this["delete"]("/0.6/relation/"+e)}}Object.defineProperty(t,"__esModule",{value:!0});var n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol?"symbol":typeof e};t["default"]=r},function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{"default":e}}Object.defineProperty(t,"__esModule",{value:!0});var i=r(5),s=n(i),o=r(6),a=n(o),u=a["default"]?a["default"].name:"ngStorage",l=angular.module("osm.settings",[u]).service("osmSettingsService",s["default"]);t["default"]=l},function(e,t){"use strict";function r(e){this.localStorage=e.$default({userName:"",userID:"",credentials:"",changeset:""}),this.getUserName=function(){return this.localStorage.userName},this.setUserName=function(e){this.localStorage.userName=e},this.getUserID=function(){return this.localStorage.userID},this.setUserID=function(e){this.localStorage.userID=e},this.getCredentials=function(){return this.localStorage.credentials},this.setCredentials=function(e){this.localStorage.credentials=e},this.getChangeset=function(){return this.localStorage.changeset},this.setChangeset=function(e){this.localStorage.changeset=e},this.getOsmAuth=function(){return this.localStorage.osmAuth},this.setOsmAuth=function(e){this.localStorage.osmAuth=e}}Object.defineProperty(t,"__esModule",{value:!0}),r.$inject=["$localStorage"],t["default"]=r},function(e,r){e.exports=t},function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{"default":e}}Object.defineProperty(t,"__esModule",{value:!0});var i=r(8),s=n(i),o=r(4),a=n(o),u=r(9),l=n(u),c=angular.module("osm.utils",[a["default"].name,l["default"].name]).service("osmUtilsService",s["default"]);t["default"]=c},function(e,t){"use strict";function r(e,t,r){this.relationToGeoJSON=function(e,t){var r=this,n=[],i=[],s={type:"FeatureCollection",properties:{id:e},options:{},members:[],features:n,relations:i},t=relationXML.getElementById(e);s.properties.visible=t.getAttribute("visible"),s.properties.version=t.getAttribute("version"),s.properties.changeset=t.getAttribute("changeset"),s.properties.timestamp=t.getAttribute("timestamp"),s.properties.user=t.getAttribute("user"),s.properties.uid=t.getAttribute("uid");var o,a,u,l,c,h,f,g,d;for(a=0;a<t.children.length;a++)if(o=t.children[a],"member"===o.tagName)if(g={type:o.getAttribute("type"),ref:o.getAttribute("ref"),role:o.getAttribute("role")},s.members.push(g),d=relationXML.getElementById(o.getAttribute("ref")),c=r.getTagsFromChildren(d),g.name=c.name,"way"===d.tagName){h=[],f={type:"Feature",properties:c,id:o.getAttribute("ref"),geometry:{type:"LineString",coordinates:h}};for(var p=0;p<d.children.length;p++)u=d.children[p],"nd"===u.tagName&&(l=relationXML.getElementById(u.getAttribute("ref")),h.push([parseFloat(l.getAttribute("lon")),parseFloat(l.getAttribute("lat"))]));n.push(f)}else"node"===d.tagName?(f={type:"Feature",properties:c,id:o.getAttribute("ref"),geometry:{type:"Point",coordinates:[parseFloat(d.getAttribute("lon")),parseFloat(d.getAttribute("lat"))]}},n.push(f)):"relation"===d.tagName&&(g.tags=c);return s.tags=r.getTagsFromChildren(t),s},this.encodeXML=function(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")},this.relationGeoJSONToXml=function(e){var r,n=e.properties,i=e.members,s=t,o='<?xml version="1.0" encoding="UTF-8"?>\n';for(o+='<osm version="0.6" generator="angular-osm 0.2" copyright="OpenStreetMap and contributors" attribution="http://www.openstreetmap.org/copyright" license="http://opendatacommons.org/licenses/odbl/1-0/">\n',o+=' <relation id="'+n.id+'" visible="'+n.visible+'" ',o+='version="'+n.version+'" ',o+='changeset="'+s.getChangeset()+'" timestamp="'+(new Date).toISOString()+'" ',o+='user="'+s.getUserName()+'" uid="'+n.uid+'">\n',r=0;r<i.length;r++)o+=' <member type="'+i[r].type+'" ',o+='ref="'+i[r].ref,o+="relation"===i[r].type?'" role="'+i[r].role+'"/>\n':'" role="'+i[r].role+'"/>\n';var a=e.tags;for(var u in a)o+=' <tag k="'+u+'" v="'+this.encodeXML(a[u])+'"/>\n';return o+=" </relation>\n",o+="</osm>"},this.sortRelationMembers=function(e){var t,r,n,i,s,o,a,u,l,c,h,f,g=e.members,d=e.features,p=[],m=function(e){p.splice(0,0,e)},y=function(e){p.push(e)},v=function(e){return d[e].geometry.coordinates},b=!1;for(r=0;r<g.length;r++)if(n=g[r],"way"===n.type){for(h=!1,s=0;s<p.length;s++)p[s].ref===n.ref&&(h=!0);if(!h){for(0===p.length&&(p.push(n),u=v(r),l=u[0],c=u[u.length-1]),f=b=!1,i=0;i<d.length;i++)if(t=d[i],"LineString"===t.geometry.type){for(h=!1,s=0;s<p.length;s++)p[s].ref===t.id&&(h=!0);h||(u=v(i),o=u[0],a=u[u.length-1],l[0]!==a[0]||l[1]!==a[1]?c[0]!==o[0]||c[1]!==o[1]?l[0]!==o[0]||l[1]!==o[1]?c[0]!==a[0]||c[1]!==a[1]||(y(g[i]),c=o,b=!0):(m(g[i]),l=a,f=!0):(y(g[i]),c=a,b=!0):(m(g[i]),l=o,f=!0))}f||b||(console.log("not found connected ways for "+n.ref),console.log(l),console.log(c))}}else p.push(n);if(g.length===p.length){e.members=p;var _={loaded:!1},j=function(e){if(!_.loaded)for(var t=0;t<d.length;t++)_[d[t].id]=d[t];return _[e]};e.features=[];for(var S=0;S<p.length;S++)e.features.push(j(p[S].ref))}else console.error("can t sort this relation");return e},this.x2js=r,this.xml2js=function(e){return r.xml2js(e)},this.js2xml=function(e){return r.js2xml(e)},this.yqlJSON=function(t){var r,n,i=$q.defer();return n={params:{q:"select * from json where url='"+t+"';",format:"json"}},r="http://query.yahooapis.com/v1/public/yql",e.get(r,n).then(function(e){null===e.data.query.results?i.resolve([]):i.resolve(e.data.query.results.json)},function(e){i.reject(e)}),i.promise},this.getElementTypeFromFeature=function(e){var t=e.geometry.type;return"LineString"===t?"way":"Point"===t?"node":void console.error("not supported type "+t)}}Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=r},function(e,t){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=angular.module("osm.x2js",[]).provider("osmx2js",function(){this.options={},this.$get=function(){return new X2JS(this.options)}});t["default"]=r},function(e,t){e.exports=r},function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{"default":e}}Object.defineProperty(t,"__esModule",{value:!0});var i=r(12),s=n(i),o=angular.module("osm.oauth",[]).factory("osmAuthService",s["default"]).provider("osmAuthService",function(){this.options={},this.$get=function(e){return new s["default"](e,this.options)},this.$get.$inject=["$q"]});t["default"]=o},function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{"default":e}}function i(e,t){t&&t.oauth_secret&&t.oauth_consumer_key&&(this.auth=osmAuth(t)),this.logout=function(){this.auth.logout()},this.authenticated=function(){return this.auth.authenticated()},this.authenticate=function(){var t=e.defer();return this.auth.authenticate(function(){t.resolve(!0)}),t.promise},this.xhr=function(t){var r=e.defer();return this.auth.xhr(t,function(e,t){e?r.reject(e):r.resolve(t)}),r.promise},this.options=function(e){this.auth?this.auth.options(e):this.auth=osmAuth(e)}}Object.defineProperty(t,"__esModule",{value:!0});var s=r(13);n(s);t["default"]=i},function(e,t){e.exports=n},function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{"default":e}}Object.defineProperty(t,"__esModule",{value:!0});var i=r(15),s=n(i),o=r(4),a=n(o),u=angular.module("osm.overpass",[a["default"].name]).factory("osmOverpassAPI",s["default"]).provider("osmOverpassAPI",function(){this.options={url:"http://overpass-api.de/api/interpreter"},this.$get=function(e,t,r){return new s["default"](e,t,r,this.options)},this.$get.$inject=["$http","$q","osmSettingsService"]});t["default"]=u},function(e,t){"use strict";function r(e,t,r,n){this.url=n.url,this.overpass=function(r){var n=this,i=n.url,s=t.defer(),o={"Content-Type":"application/x-www-form-urlencoded; charset=UTF-8"};return e.post(i,"data="+encodeURIComponent(r),{headers:o}).then(function(e){s.resolve(e.data)},function(e){s.reject(e)}),s.promise},this.getAreaId=function(e,t){var r;return r="string"==typeof t?parseInt(t,10):t,"r"===e||"relation"===e?36e8+r:"w"===e||"way"===e?24e8+r:void 0},this.overpassToGeoJSON=function(e,r){var n=t.defer(),i=[],s=[],o={type:"FeatureCollection",features:i,relations:s};return void 0===r&&(r=function(){}),this.overpass(e).then(function(e){function t(t){if(!l.loaded)for(var r,n=0;n<e.elements.length;n++)r=e.elements[n],l[r.id]=r;return l[t]}for(var s,a,u,l={loaded:!1},c=0;c<e.elements.length;c++)if(s=e.elements[c],"node"===s.type)a={type:"Feature",properties:s.tags,id:s.id,geometry:{type:"Point",coordinates:[s.lon,s.lat]}},r(a)||i.push(a);else if("way"===s.type){u=[],a={type:"Feature",properties:s.tags,id:s.id,geometry:{type:"LineString",coordinates:u}};for(var h=0;h<s.nodes.length;h++)u.push([t(s.nodes[h]).lon,t(s.nodes[h]).lat]);r(a)||i.push(a)}else"relation"===s.type&&o.relations.push({ref:s.id,tags:s.tags,type:"relation",members:s.members});n.resolve(o)},function(e){n.reject(e)}),n.promise}}Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=r},function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{"default":e}}Object.defineProperty(t,"__esModule",{value:!0});var i=r(17),s=n(i),o=angular.module("osm.taginfo",[]).service("osmTagInfoAPI",s["default"]);t["default"]=o},function(e,t){"use strict";function r(e,t){this.get=function(r,n){var i=t.defer();return e.get("https://taginfo.openstreetmap.org/api/4"+r,n).then(function(e){i.resolve(e.data)},function(e){i.reject(e)}),i.promise},this.getKeyCombinations=function(e){return this.get("/key/combinations",{params:e})},this.getKeyDistributionNodes=function(e){return this.get("/key/distribution/nodes",{params:e})},this.getKeyDistributionWays=function(e){return this.get("/key/distribution/ways",{params:e})},this.getKeyStats=function(e){return this.get("/key/stats",{params:e})},this.getKeyValues=function(e){return this.get("/key/values",{params:e})},this.getKeyWikiPages=function(e){return this.get("/key/wiki_pages",{params:e})},this.getKeysAll=function(e){return this.get("/keys/all",{params:e})},this.getKeysWikiPages=function(e){return this.get("/keys/wiki_pages",{params:e})},this.getKeysWithoutWikiPage=function(e){return this.get("/keys/without_wiki_page",{params:e})},this.getRelationRoles=function(e){return this.get("/relation/roles",{params:e})},this.getRelationStats=function(e){return this.get("/relation/stats",{params:e})},this.getRelationWikiPages=function(e){return this.get("/relation/wiki_pages",{params:e})},this.getRelationsAll=function(e){return this.get("/relations/all",{params:e})},this.getSearchByKeyAndValue=function(e){return this.get("/search/by_key_and_value",{params:e})},this.getSearchByKeyword=function(e){return this.get("/search/by_keyword",{params:e})},this.getSearchByRole=function(e){return this.get("/search/by_role",{params:e})},this.getSearchByValue=function(e){return this.get("/search/by_value",{params:e})},this.getSiteInfo=function(e){return this.get("/site/info",{params:e})},this.getSiteSources=function(e){return this.get("/site/sources",{params:e})},this.getTagCombinations=function(e){return this.get("/tag/combinations",{params:e})},this.getTagDistributionNodes=function(e){return this.get("/tag/distribution/nodes",{params:e})},this.getTagDistributionWays=function(e){return this.get("/tag/distribution/ways",{params:e})},this.getTagStats=function(e){return this.get("/tag/stats",{params:e})},this.getTagWikiPages=function(e){return this.get("/tag/wiki_pages",{params:e})},this.getTagsPopular=function(e){return this.get("/tags/popular",{params:e})},this.getWikiLanguages=function(e){return this.get("/wiki/languages",{params:e})}}Object.defineProperty(t,"__esModule",{value:!0}),r.$inject=["$http","$q"],t["default"]=r},function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{"default":e}}Object.defineProperty(t,"__esModule",{value:!0});var i=r(19),s=n(i),o=angular.module("osm.nominatim",[]).factory("osmNominatim",s["default"]).provider("osmNominatim",function(){this.options={url:"https://nominatim.openstreetmap.org"},this.$get=function(e){return new s["default"](e,this.options)},this.$get.$inject=["$http"]});t["default"]=o},function(e,t){"use strict";function r(e,t){this.url=t.url,this.search=function(t){var r;"string"!=typeof t&&t?(r=angular.copy(t),r.format="json"):r={format:"json",q:t};var n={params:r},i=this.url+"/search";return e.get(i,n)},this.reverse=function(t){var r;"string"==typeof t?r={format:"json",q:t}:(r=angular.copy(t),r.format="json");var n={params:r},i=this.url+"/reverse";return e.get(i,n)},this.lookup=function(t){var r;"string"==typeof t?r={format:"json",q:t}:(r=angular.copy(t),r.format="json");var n={params:r},i=this.url+"/lookup";return e.get(i,n)}}Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=r}])}); |
@@ -10,3 +10,3 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
root["angular-osm"] = root["angular-osm"] || {}, root["angular-osm"]["name"] = factory(root["osm-auth"]); | ||
})(this, function(__WEBPACK_EXTERNAL_MODULE_12__) { | ||
})(this, function(__WEBPACK_EXTERNAL_MODULE_13__) { | ||
return /******/ (function(modules) { // webpackBootstrap | ||
@@ -58,3 +58,3 @@ /******/ // The module cache | ||
module.exports = __webpack_require__(10); | ||
module.exports = __webpack_require__(11); | ||
@@ -72,3 +72,4 @@ | ||
/* 9 */, | ||
/* 10 */ | ||
/* 10 */, | ||
/* 11 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
@@ -82,3 +83,3 @@ | ||
var _oauth = __webpack_require__(11); | ||
var _oauth = __webpack_require__(12); | ||
@@ -101,3 +102,3 @@ var _oauth2 = _interopRequireDefault(_oauth); | ||
/***/ }, | ||
/* 11 */ | ||
/* 12 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
@@ -111,3 +112,3 @@ | ||
var _osmAuth = __webpack_require__(12); | ||
var _osmAuth = __webpack_require__(13); | ||
@@ -130,8 +131,25 @@ var _osmAuth2 = _interopRequireDefault(_osmAuth); | ||
} | ||
/** | ||
* @ngdoc method | ||
* @name logout | ||
* @methodOf osm.auth.osmAuthService | ||
*/ | ||
this.logout = function () { | ||
return this.auth.logout(); | ||
this.auth.logout(); | ||
}; | ||
/** | ||
* @ngdoc method | ||
* @name authenticated | ||
* @methodOf osm.auth.osmAuthService | ||
* @return {boolean} authenticated | ||
*/ | ||
this.authenticated = function () { | ||
return this.auth.authenticated(); | ||
}; | ||
/** | ||
* @ngdoc method | ||
* @name authenticate | ||
* @methodOf osm.auth.osmAuthService | ||
* @return {Promise} true/false | ||
*/ | ||
this.authenticate = function () { | ||
@@ -144,2 +162,8 @@ var deferred = $q.defer(); | ||
}; | ||
/** | ||
* @ngdoc method | ||
* @name xhr | ||
* @methodOf osm.auth.osmAuthService | ||
* @return {Promise} http response | ||
*/ | ||
this.xhr = function (options) { | ||
@@ -156,2 +180,7 @@ var deferred = $q.defer(); | ||
}; | ||
/** | ||
* @ngdoc method | ||
* @name options | ||
* @methodOf osm.auth.osmAuthService | ||
*/ | ||
this.options = function (options) { | ||
@@ -169,6 +198,6 @@ if (this.auth) { | ||
/***/ }, | ||
/* 12 */ | ||
/* 13 */ | ||
/***/ function(module, exports) { | ||
module.exports = __WEBPACK_EXTERNAL_MODULE_12__; | ||
module.exports = __WEBPACK_EXTERNAL_MODULE_13__; | ||
@@ -175,0 +204,0 @@ /***/ } |
@@ -1,1 +0,1 @@ | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("osm-auth")):"function"==typeof define&&define.amd?define(["osm-auth"],e):"object"==typeof exports?exports.name=e(require("osm-auth")):(t["angular-osm"]=t["angular-osm"]||{},t["angular-osm"].name=e(t["osm-auth"]))}(this,function(t){return function(t){function e(u){if(o[u])return o[u].exports;var n=o[u]={exports:{},id:u,loaded:!1};return t[u].call(n.exports,n,n.exports,e),n.loaded=!0,n.exports}var o={};return e.m=t,e.c=o,e.p="",e(0)}([function(t,e,o){t.exports=o(10)},,,,,,,,,,function(t,e,o){"use strict";function u(t){return t&&t.__esModule?t:{"default":t}}Object.defineProperty(e,"__esModule",{value:!0});var n=o(11),r=u(n),i=angular.module("osm.oauth",[]).factory("osmAuthService",r["default"]).provider("osmAuthService",function(){this.options={},this.$get=function(t){return new r["default"](t,this.options)},this.$get.$inject=["$q"]});e["default"]=i},function(t,e,o){"use strict";function u(t){return t&&t.__esModule?t:{"default":t}}function n(t,e){e&&e.oauth_secret&&e.oauth_consumer_key&&(this.auth=osmAuth(e)),this.logout=function(){return this.auth.logout()},this.authenticated=function(){return this.auth.authenticated()},this.authenticate=function(){var e=t.defer();return this.auth.authenticate(function(){e.resolve(!0)}),e.promise},this.xhr=function(e){var o=t.defer();return this.auth.xhr(e,function(t,e){t?o.reject(t):o.resolve(e)}),o.promise},this.options=function(t){this.auth?this.auth.options(t):this.auth=osmAuth(t)}}Object.defineProperty(e,"__esModule",{value:!0});var r=o(12);u(r);e["default"]=n},function(e,o){e.exports=t}])}); | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("osm-auth")):"function"==typeof define&&define.amd?define(["osm-auth"],e):"object"==typeof exports?exports.name=e(require("osm-auth")):(t["angular-osm"]=t["angular-osm"]||{},t["angular-osm"].name=e(t["osm-auth"]))}(this,function(t){return function(t){function e(u){if(o[u])return o[u].exports;var n=o[u]={exports:{},id:u,loaded:!1};return t[u].call(n.exports,n,n.exports,e),n.loaded=!0,n.exports}var o={};return e.m=t,e.c=o,e.p="",e(0)}([function(t,e,o){t.exports=o(11)},,,,,,,,,,,function(t,e,o){"use strict";function u(t){return t&&t.__esModule?t:{"default":t}}Object.defineProperty(e,"__esModule",{value:!0});var n=o(12),r=u(n),i=angular.module("osm.oauth",[]).factory("osmAuthService",r["default"]).provider("osmAuthService",function(){this.options={},this.$get=function(t){return new r["default"](t,this.options)},this.$get.$inject=["$q"]});e["default"]=i},function(t,e,o){"use strict";function u(t){return t&&t.__esModule?t:{"default":t}}function n(t,e){e&&e.oauth_secret&&e.oauth_consumer_key&&(this.auth=osmAuth(e)),this.logout=function(){this.auth.logout()},this.authenticated=function(){return this.auth.authenticated()},this.authenticate=function(){var e=t.defer();return this.auth.authenticate(function(){e.resolve(!0)}),e.promise},this.xhr=function(e){var o=t.defer();return this.auth.xhr(e,function(t,e){t?o.reject(t):o.resolve(e)}),o.promise},this.options=function(t){this.auth?this.auth.options(t):this.auth=osmAuth(t)}}Object.defineProperty(e,"__esModule",{value:!0});var r=o(13);u(r);e["default"]=n},function(e,o){e.exports=t}])}); |
@@ -57,3 +57,3 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
module.exports = __webpack_require__(13); | ||
module.exports = __webpack_require__(14); | ||
@@ -86,3 +86,3 @@ | ||
var osmSettingsModule = angular.module('osm.settings', [ngStorageModuleName]).factory('osmSettingsService', _settings2.default); | ||
var osmSettingsModule = angular.module('osm.settings', [ngStorageModuleName]).service('osmSettingsService', _settings2.default); | ||
@@ -101,3 +101,2 @@ exports.default = osmSettingsModule; | ||
/** | ||
@@ -111,70 +110,39 @@ * @ngdoc service | ||
function osmSettingsService($localStorage) { | ||
return { | ||
localStorage: $localStorage.$default({ | ||
userName: '', | ||
userID: '', | ||
credentials: '', | ||
nodes: [], | ||
changeset: '', | ||
osmAPI: '', | ||
overpassAPI: '' | ||
}), | ||
getUserName: function getUserName() { | ||
return this.localStorage.userName; | ||
}, | ||
setUserName: function setUserName(username) { | ||
this.localStorage.userName = username; | ||
}, | ||
getUserID: function getUserID() { | ||
return this.localStorage.userID; | ||
}, | ||
setUserID: function setUserID(userid) { | ||
this.localStorage.userID = userid; | ||
}, | ||
getCredentials: function getCredentials() { | ||
return this.localStorage.credentials; | ||
}, | ||
setCredentials: function setCredentials(credentials) { | ||
this.localStorage.credentials = credentials; | ||
}, | ||
getOSMAPI: function getOSMAPI() { | ||
if (this.localStorage.osmAPI) { | ||
return this.localStorage.osmAPI; | ||
} else { | ||
return 'http://api.openstreetmap.org/api'; | ||
} | ||
}, | ||
setOSMAPI: function setOSMAPI(osmAPI) { | ||
this.localStorage.osmAPI = osmAPI; | ||
}, | ||
getOverpassAPI: function getOverpassAPI() { | ||
if (this.localStorage.overpassAPI) { | ||
return this.localStorage.overpassAPI; | ||
} else { | ||
//return 'http://api.openstreetmap.org/api'; | ||
return 'http://overpass-api.de/api/interpreter'; | ||
} | ||
}, | ||
setOverpassAPI: function setOverpassAPI(overpassAPI) { | ||
this.localStorage.overpassAPI = overpassAPI; | ||
}, | ||
getNodes: function getNodes() { | ||
return this.localStorage.nodes; | ||
}, | ||
setNodes: function setNodes(nodes) { | ||
this.localStorage.nodes = nodes; | ||
}, | ||
getChangeset: function getChangeset() { | ||
return this.localStorage.changeset; | ||
}, | ||
setChangeset: function setChangeset(changeset) { | ||
this.localStorage.changeset = changeset; | ||
}, | ||
getOsmAuth: function getOsmAuth() { | ||
return this.localStorage.osmAuth; | ||
}, | ||
setOsmAuth: function setOsmAuth(options) { | ||
return this.localStorage.osmAuth = options; | ||
} | ||
this.localStorage = $localStorage.$default({ | ||
userName: '', | ||
userID: '', | ||
credentials: '', | ||
changeset: '' | ||
}); | ||
this.getUserName = function () { | ||
return this.localStorage.userName; | ||
}; | ||
this.setUserName = function (username) { | ||
this.localStorage.userName = username; | ||
}; | ||
this.getUserID = function () { | ||
return this.localStorage.userID; | ||
}; | ||
this.setUserID = function (userid) { | ||
this.localStorage.userID = userid; | ||
}; | ||
this.getCredentials = function () { | ||
return this.localStorage.credentials; | ||
}; | ||
this.setCredentials = function (credentials) { | ||
this.localStorage.credentials = credentials; | ||
}; | ||
this.getChangeset = function () { | ||
return this.localStorage.changeset; | ||
}; | ||
this.setChangeset = function (changeset) { | ||
this.localStorage.changeset = changeset; | ||
}; | ||
this.getOsmAuth = function () { | ||
return this.localStorage.osmAuth; | ||
}; | ||
this.setOsmAuth = function (options) { | ||
this.localStorage.osmAuth = options; | ||
}; | ||
} | ||
@@ -197,3 +165,4 @@ | ||
/* 12 */, | ||
/* 13 */ | ||
/* 13 */, | ||
/* 14 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
@@ -204,6 +173,6 @@ | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
value: true | ||
}); | ||
var _overpass = __webpack_require__(14); | ||
var _overpass = __webpack_require__(15); | ||
@@ -218,3 +187,11 @@ var _overpass2 = _interopRequireDefault(_overpass); | ||
var osmOverpassModule = angular.module('osm.overpass', [_settings2.default.name]).factory('osmOverpassAPI', _overpass2.default); | ||
var osmOverpassModule = angular.module('osm.overpass', [_settings2.default.name]).factory('osmOverpassAPI', _overpass2.default).provider('osmOverpassAPI', function osmOverpassAPIProvider() { | ||
this.options = { | ||
url: 'http://overpass-api.de/api/interpreter' | ||
}; | ||
this.$get = function osmOverpassAPIFactory($http, $q, osmSettingsService) { | ||
return new _overpass2.default($http, $q, osmSettingsService, this.options); | ||
}; | ||
this.$get.$inject = ['$http', '$q', 'osmSettingsService']; | ||
}); | ||
@@ -224,3 +201,3 @@ exports.default = osmOverpassModule; | ||
/***/ }, | ||
/* 14 */ | ||
/* 15 */ | ||
/***/ function(module, exports) { | ||
@@ -242,92 +219,121 @@ | ||
*/ | ||
osmOverpassAPI.$inject = ['$http', '$q', 'osmSettingsService']; | ||
function osmOverpassAPI($http, $q, osmSettingsService) { | ||
var service = { | ||
overpass: function overpass(query) { | ||
var url = osmSettingsService.getOverpassAPI(); | ||
var deferred = $q.defer(); | ||
var self = this; | ||
var headers = { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' }; | ||
$http.post(url, 'data=' + encodeURIComponent(query), { headers: headers }).then(function (data) { | ||
deferred.resolve(data.data); | ||
}, function (data) { | ||
deferred.reject(data); | ||
}); | ||
return deferred.promise; | ||
}, | ||
overpassToGeoJSON: function overpassToGeoJSON(query, filter) { | ||
var deferred = $q.defer(); | ||
var features = []; | ||
var relations = []; | ||
var result = { | ||
type: 'FeatureCollection', | ||
features: features, | ||
relations: relations | ||
function osmOverpassAPI($http, $q, osmSettingsService, options) { | ||
this.url = options.url; | ||
/** | ||
* @ngdoc method | ||
* @name overpass | ||
* @param {Object/String} query | ||
* http://wiki.openstreetmap.org/wiki/FR:Overpass_API | ||
* @methodOf osm.overpass.osmOverpassAPI | ||
* @return {Promise} $http.get | ||
*/ | ||
this.overpass = function (query) { | ||
var self = this; | ||
var url = self.url; | ||
var deferred = $q.defer(); | ||
var headers = { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' }; | ||
$http.post(url, 'data=' + encodeURIComponent(query), { headers: headers }).then(function (data) { | ||
deferred.resolve(data.data); | ||
}, function (data) { | ||
deferred.reject(data); | ||
}); | ||
return deferred.promise; | ||
}; | ||
/** | ||
* @ngdoc method | ||
* @name overpass | ||
* @description | ||
* http://wiki.openstreetmap.org/wiki/FR:Overpass_API/Overpass_QL#By_area_.28area.29 | ||
By convention the area id can be calculated from an existing OSM way by adding 2400000000 to its OSM id, or in case of a relation by adding 3600000000 respectively. Note that area creation is subject to some extraction rules, i.e. not all ways/relations have an area counterpart (notably those that are tagged with area=no, and most multipolygons and that don't have a defined name=* will not be part of areas). | ||
* @param {String} type 'r'/'relation' or 'w'/'way' | ||
* @param {String/Number} osmId the id of the element | ||
* @methodOf osm.overpass.osmOverpassAPI | ||
* @return {Number} the area id | ||
*/ | ||
this.getAreaId = function (type, osmId) { | ||
var id; | ||
if (typeof osmId === 'string') { | ||
id = parseInt(osmId, 10); | ||
} else { | ||
id = osmId; | ||
} | ||
if (type === 'r' || type === 'relation') { | ||
return 3600000000 + id; | ||
} else if (type === 'w' || type === 'way') { | ||
return 2400000000 + id; | ||
} | ||
}; | ||
this.overpassToGeoJSON = function (query, filter) { | ||
var deferred = $q.defer(); | ||
var features = []; | ||
var relations = []; | ||
var result = { | ||
type: 'FeatureCollection', | ||
features: features, | ||
relations: relations | ||
}; | ||
if (filter === undefined) { | ||
filter = function filter() {}; | ||
} | ||
this.overpass(query).then(function (data) { | ||
//TODO check if data is XML or JSON, here it's JSON | ||
var node, feature, coordinates; | ||
var cache = { loaded: false }; | ||
function getNodeById(id) { | ||
if (!cache.loaded) { | ||
var tmp; | ||
for (var i = 0; i < data.elements.length; i++) { | ||
tmp = data.elements[i]; | ||
cache[tmp.id] = tmp; | ||
} | ||
} | ||
return cache[id]; | ||
}; | ||
if (filter === undefined) { | ||
filter = function filter() {}; | ||
} | ||
this.overpass(query).then(function (data) { | ||
//TODO check if data is XML or JSON, here it's JSON | ||
var node, feature, coordinates; | ||
var cache = { loaded: false }; | ||
function getNodeById(id) { | ||
if (!cache.loaded) { | ||
var tmp; | ||
for (var i = 0; i < data.elements.length; i++) { | ||
tmp = data.elements[i]; | ||
cache[tmp.id] = tmp; | ||
for (var i = 0; i < data.elements.length; i++) { | ||
node = data.elements[i]; | ||
if (node.type === 'node') { | ||
feature = { | ||
type: 'Feature', | ||
properties: node.tags, | ||
id: node.id, | ||
geometry: { | ||
type: 'Point', | ||
coordinates: [node.lon, node.lat] | ||
} | ||
}; | ||
if (!filter(feature)) { | ||
features.push(feature); | ||
} | ||
return cache[id]; | ||
}; | ||
for (var i = 0; i < data.elements.length; i++) { | ||
node = data.elements[i]; | ||
if (node.type === 'node') { | ||
feature = { | ||
type: 'Feature', | ||
properties: node.tags, | ||
id: node.id, | ||
geometry: { | ||
type: 'Point', | ||
coordinates: [node.lon, node.lat] | ||
} | ||
}; | ||
if (!filter(feature)) { | ||
features.push(feature); | ||
} else if (node.type === 'way') { | ||
coordinates = []; | ||
feature = { | ||
type: 'Feature', | ||
properties: node.tags, | ||
id: node.id, | ||
geometry: { | ||
type: 'LineString', | ||
coordinates: coordinates | ||
} | ||
} else if (node.type === 'way') { | ||
coordinates = []; | ||
feature = { | ||
type: 'Feature', | ||
properties: node.tags, | ||
id: node.id, | ||
geometry: { | ||
type: 'LineString', | ||
coordinates: coordinates | ||
} | ||
}; | ||
for (var j = 0; j < node.nodes.length; j++) { | ||
coordinates.push([getNodeById(node.nodes[j]).lon, getNodeById(node.nodes[j]).lat]); | ||
} | ||
if (!filter(feature)) { | ||
features.push(feature); | ||
} | ||
} else if (node.type === 'relation') { | ||
result.relations.push({ | ||
ref: node.id, | ||
tags: node.tags, | ||
type: 'relation', | ||
members: node.members | ||
}); | ||
}; | ||
for (var j = 0; j < node.nodes.length; j++) { | ||
coordinates.push([getNodeById(node.nodes[j]).lon, getNodeById(node.nodes[j]).lat]); | ||
} | ||
if (!filter(feature)) { | ||
features.push(feature); | ||
} | ||
} else if (node.type === 'relation') { | ||
result.relations.push({ | ||
ref: node.id, | ||
tags: node.tags, | ||
type: 'relation', | ||
members: node.members | ||
}); | ||
} | ||
deferred.resolve(result); | ||
}, function (error) { | ||
deferred.reject(error); | ||
}); | ||
return deferred.promise; | ||
} | ||
} | ||
deferred.resolve(result); | ||
}, function (error) { | ||
deferred.reject(error); | ||
}); | ||
return deferred.promise; | ||
}; | ||
return service; | ||
} | ||
@@ -334,0 +340,0 @@ |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("ngstorage")):"function"==typeof define&&define.amd?define(["ngstorage"],t):"object"==typeof exports?exports.name=t(require("ngstorage")):(e["angular-osm"]=e["angular-osm"]||{},e["angular-osm"].name=t(e.ngstorage))}(this,function(e){return function(e){function t(r){if(o[r])return o[r].exports;var n=o[r]={exports:{},id:r,loaded:!1};return e[r].call(n.exports,n,n.exports,t),n.loaded=!0,n.exports}var o={};return t.m=e,t.c=o,t.p="",t(0)}([function(e,t,o){e.exports=o(13)},,,,function(e,t,o){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}Object.defineProperty(t,"__esModule",{value:!0});var n=o(5),s=r(n),a=o(6),i=r(a),u=i["default"]?i["default"].name:"ngStorage",l=angular.module("osm.settings",[u]).factory("osmSettingsService",s["default"]);t["default"]=l},function(e,t){"use strict";function o(e){return{localStorage:e.$default({userName:"",userID:"",credentials:"",nodes:[],changeset:"",osmAPI:"",overpassAPI:""}),getUserName:function(){return this.localStorage.userName},setUserName:function(e){this.localStorage.userName=e},getUserID:function(){return this.localStorage.userID},setUserID:function(e){this.localStorage.userID=e},getCredentials:function(){return this.localStorage.credentials},setCredentials:function(e){this.localStorage.credentials=e},getOSMAPI:function(){return this.localStorage.osmAPI?this.localStorage.osmAPI:"http://api.openstreetmap.org/api"},setOSMAPI:function(e){this.localStorage.osmAPI=e},getOverpassAPI:function(){return this.localStorage.overpassAPI?this.localStorage.overpassAPI:"http://overpass-api.de/api/interpreter"},setOverpassAPI:function(e){this.localStorage.overpassAPI=e},getNodes:function(){return this.localStorage.nodes},setNodes:function(e){this.localStorage.nodes=e},getChangeset:function(){return this.localStorage.changeset},setChangeset:function(e){this.localStorage.changeset=e},getOsmAuth:function(){return this.localStorage.osmAuth},setOsmAuth:function(e){return this.localStorage.osmAuth=e}}}Object.defineProperty(t,"__esModule",{value:!0}),o.$inject=["$localStorage"],t["default"]=o},function(t,o){t.exports=e},,,,,,,function(e,t,o){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}Object.defineProperty(t,"__esModule",{value:!0});var n=o(14),s=r(n),a=o(4),i=r(a),u=angular.module("osm.overpass",[i["default"].name]).factory("osmOverpassAPI",s["default"]);t["default"]=u},function(e,t){"use strict";function o(e,t,o){var r={overpass:function(r){var n=o.getOverpassAPI(),s=t.defer(),a={"Content-Type":"application/x-www-form-urlencoded; charset=UTF-8"};return e.post(n,"data="+encodeURIComponent(r),{headers:a}).then(function(e){s.resolve(e.data)},function(e){s.reject(e)}),s.promise},overpassToGeoJSON:function(e,o){var r=t.defer(),n=[],s=[],a={type:"FeatureCollection",features:n,relations:s};return void 0===o&&(o=function(){}),this.overpass(e).then(function(e){function t(t){if(!l.loaded)for(var o,r=0;r<e.elements.length;r++)o=e.elements[r],l[o.id]=o;return l[t]}for(var s,i,u,l={loaded:!1},c=0;c<e.elements.length;c++)if(s=e.elements[c],"node"===s.type)i={type:"Feature",properties:s.tags,id:s.id,geometry:{type:"Point",coordinates:[s.lon,s.lat]}},o(i)||n.push(i);else if("way"===s.type){u=[],i={type:"Feature",properties:s.tags,id:s.id,geometry:{type:"LineString",coordinates:u}};for(var f=0;f<s.nodes.length;f++)u.push([t(s.nodes[f]).lon,t(s.nodes[f]).lat]);o(i)||n.push(i)}else"relation"===s.type&&a.relations.push({ref:s.id,tags:s.tags,type:"relation",members:s.members});r.resolve(a)},function(e){r.reject(e)}),r.promise}};return r}Object.defineProperty(t,"__esModule",{value:!0}),o.$inject=["$http","$q","osmSettingsService"],t["default"]=o}])}); | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("ngstorage")):"function"==typeof define&&define.amd?define(["ngstorage"],t):"object"==typeof exports?exports.name=t(require("ngstorage")):(e["angular-osm"]=e["angular-osm"]||{},e["angular-osm"].name=t(e.ngstorage))}(this,function(e){return function(e){function t(o){if(r[o])return r[o].exports;var n=r[o]={exports:{},id:o,loaded:!1};return e[o].call(n.exports,n,n.exports,t),n.loaded=!0,n.exports}var r={};return t.m=e,t.c=r,t.p="",t(0)}([function(e,t,r){e.exports=r(14)},,,,function(e,t,r){"use strict";function o(e){return e&&e.__esModule?e:{"default":e}}Object.defineProperty(t,"__esModule",{value:!0});var n=r(5),s=o(n),i=r(6),a=o(i),u=a["default"]?a["default"].name:"ngStorage",l=angular.module("osm.settings",[u]).service("osmSettingsService",s["default"]);t["default"]=l},function(e,t){"use strict";function r(e){this.localStorage=e.$default({userName:"",userID:"",credentials:"",changeset:""}),this.getUserName=function(){return this.localStorage.userName},this.setUserName=function(e){this.localStorage.userName=e},this.getUserID=function(){return this.localStorage.userID},this.setUserID=function(e){this.localStorage.userID=e},this.getCredentials=function(){return this.localStorage.credentials},this.setCredentials=function(e){this.localStorage.credentials=e},this.getChangeset=function(){return this.localStorage.changeset},this.setChangeset=function(e){this.localStorage.changeset=e},this.getOsmAuth=function(){return this.localStorage.osmAuth},this.setOsmAuth=function(e){this.localStorage.osmAuth=e}}Object.defineProperty(t,"__esModule",{value:!0}),r.$inject=["$localStorage"],t["default"]=r},function(t,r){t.exports=e},,,,,,,,function(e,t,r){"use strict";function o(e){return e&&e.__esModule?e:{"default":e}}Object.defineProperty(t,"__esModule",{value:!0});var n=r(15),s=o(n),i=r(4),a=o(i),u=angular.module("osm.overpass",[a["default"].name]).factory("osmOverpassAPI",s["default"]).provider("osmOverpassAPI",function(){this.options={url:"http://overpass-api.de/api/interpreter"},this.$get=function(e,t,r){return new s["default"](e,t,r,this.options)},this.$get.$inject=["$http","$q","osmSettingsService"]});t["default"]=u},function(e,t){"use strict";function r(e,t,r,o){this.url=o.url,this.overpass=function(r){var o=this,n=o.url,s=t.defer(),i={"Content-Type":"application/x-www-form-urlencoded; charset=UTF-8"};return e.post(n,"data="+encodeURIComponent(r),{headers:i}).then(function(e){s.resolve(e.data)},function(e){s.reject(e)}),s.promise},this.getAreaId=function(e,t){var r;return r="string"==typeof t?parseInt(t,10):t,"r"===e||"relation"===e?36e8+r:"w"===e||"way"===e?24e8+r:void 0},this.overpassToGeoJSON=function(e,r){var o=t.defer(),n=[],s=[],i={type:"FeatureCollection",features:n,relations:s};return void 0===r&&(r=function(){}),this.overpass(e).then(function(e){function t(t){if(!l.loaded)for(var r,o=0;o<e.elements.length;o++)r=e.elements[o],l[r.id]=r;return l[t]}for(var s,a,u,l={loaded:!1},c=0;c<e.elements.length;c++)if(s=e.elements[c],"node"===s.type)a={type:"Feature",properties:s.tags,id:s.id,geometry:{type:"Point",coordinates:[s.lon,s.lat]}},r(a)||n.push(a);else if("way"===s.type){u=[],a={type:"Feature",properties:s.tags,id:s.id,geometry:{type:"LineString",coordinates:u}};for(var f=0;f<s.nodes.length;f++)u.push([t(s.nodes[f]).lon,t(s.nodes[f]).lat]);r(a)||n.push(a)}else"relation"===s.type&&i.relations.push({ref:s.id,tags:s.tags,type:"relation",members:s.members});o.resolve(i)},function(e){o.reject(e)}),o.promise}}Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=r}])}); |
@@ -58,3 +58,3 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
module.exports = __webpack_require__(15); | ||
module.exports = __webpack_require__(16); | ||
@@ -64,3 +64,3 @@ | ||
/***/ 15: | ||
/***/ 16: | ||
/***/ function(module, exports, __webpack_require__) { | ||
@@ -74,3 +74,3 @@ | ||
var _taginfo = __webpack_require__(16); | ||
var _taginfo = __webpack_require__(17); | ||
@@ -87,3 +87,3 @@ var _taginfo2 = _interopRequireDefault(_taginfo); | ||
/***/ 16: | ||
/***/ 17: | ||
/***/ function(module, exports) { | ||
@@ -90,0 +90,0 @@ |
@@ -1,1 +0,1 @@ | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.name=e():(t["angular-osm"]=t["angular-osm"]||{},t["angular-osm"].name=e())}(this,function(){return function(t){function e(s){if(i[s])return i[s].exports;var n=i[s]={exports:{},id:s,loaded:!1};return t[s].call(n.exports,n,n.exports,e),n.loaded=!0,n.exports}var i={};return e.m=t,e.c=i,e.p="",e(0)}({0:function(t,e,i){t.exports=i(15)},15:function(t,e,i){"use strict";function s(t){return t&&t.__esModule?t:{"default":t}}Object.defineProperty(e,"__esModule",{value:!0});var n=i(16),a=s(n),r=angular.module("osm.taginfo",[]).service("osmTagInfoAPI",a["default"]);e["default"]=r},16:function(t,e){"use strict";function i(t,e){this.get=function(i,s){var n=e.defer();return t.get("https://taginfo.openstreetmap.org/api/4"+i,s).then(function(t){n.resolve(t.data)},function(t){n.reject(t)}),n.promise},this.getKeyCombinations=function(t){return this.get("/key/combinations",{params:t})},this.getKeyDistributionNodes=function(t){return this.get("/key/distribution/nodes",{params:t})},this.getKeyDistributionWays=function(t){return this.get("/key/distribution/ways",{params:t})},this.getKeyStats=function(t){return this.get("/key/stats",{params:t})},this.getKeyValues=function(t){return this.get("/key/values",{params:t})},this.getKeyWikiPages=function(t){return this.get("/key/wiki_pages",{params:t})},this.getKeysAll=function(t){return this.get("/keys/all",{params:t})},this.getKeysWikiPages=function(t){return this.get("/keys/wiki_pages",{params:t})},this.getKeysWithoutWikiPage=function(t){return this.get("/keys/without_wiki_page",{params:t})},this.getRelationRoles=function(t){return this.get("/relation/roles",{params:t})},this.getRelationStats=function(t){return this.get("/relation/stats",{params:t})},this.getRelationWikiPages=function(t){return this.get("/relation/wiki_pages",{params:t})},this.getRelationsAll=function(t){return this.get("/relations/all",{params:t})},this.getSearchByKeyAndValue=function(t){return this.get("/search/by_key_and_value",{params:t})},this.getSearchByKeyword=function(t){return this.get("/search/by_keyword",{params:t})},this.getSearchByRole=function(t){return this.get("/search/by_role",{params:t})},this.getSearchByValue=function(t){return this.get("/search/by_value",{params:t})},this.getSiteInfo=function(t){return this.get("/site/info",{params:t})},this.getSiteSources=function(t){return this.get("/site/sources",{params:t})},this.getTagCombinations=function(t){return this.get("/tag/combinations",{params:t})},this.getTagDistributionNodes=function(t){return this.get("/tag/distribution/nodes",{params:t})},this.getTagDistributionWays=function(t){return this.get("/tag/distribution/ways",{params:t})},this.getTagStats=function(t){return this.get("/tag/stats",{params:t})},this.getTagWikiPages=function(t){return this.get("/tag/wiki_pages",{params:t})},this.getTagsPopular=function(t){return this.get("/tags/popular",{params:t})},this.getWikiLanguages=function(t){return this.get("/wiki/languages",{params:t})}}Object.defineProperty(e,"__esModule",{value:!0}),i.$inject=["$http","$q"],e["default"]=i}})}); | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.name=e():(t["angular-osm"]=t["angular-osm"]||{},t["angular-osm"].name=e())}(this,function(){return function(t){function e(s){if(i[s])return i[s].exports;var n=i[s]={exports:{},id:s,loaded:!1};return t[s].call(n.exports,n,n.exports,e),n.loaded=!0,n.exports}var i={};return e.m=t,e.c=i,e.p="",e(0)}({0:function(t,e,i){t.exports=i(16)},16:function(t,e,i){"use strict";function s(t){return t&&t.__esModule?t:{"default":t}}Object.defineProperty(e,"__esModule",{value:!0});var n=i(17),a=s(n),r=angular.module("osm.taginfo",[]).service("osmTagInfoAPI",a["default"]);e["default"]=r},17:function(t,e){"use strict";function i(t,e){this.get=function(i,s){var n=e.defer();return t.get("https://taginfo.openstreetmap.org/api/4"+i,s).then(function(t){n.resolve(t.data)},function(t){n.reject(t)}),n.promise},this.getKeyCombinations=function(t){return this.get("/key/combinations",{params:t})},this.getKeyDistributionNodes=function(t){return this.get("/key/distribution/nodes",{params:t})},this.getKeyDistributionWays=function(t){return this.get("/key/distribution/ways",{params:t})},this.getKeyStats=function(t){return this.get("/key/stats",{params:t})},this.getKeyValues=function(t){return this.get("/key/values",{params:t})},this.getKeyWikiPages=function(t){return this.get("/key/wiki_pages",{params:t})},this.getKeysAll=function(t){return this.get("/keys/all",{params:t})},this.getKeysWikiPages=function(t){return this.get("/keys/wiki_pages",{params:t})},this.getKeysWithoutWikiPage=function(t){return this.get("/keys/without_wiki_page",{params:t})},this.getRelationRoles=function(t){return this.get("/relation/roles",{params:t})},this.getRelationStats=function(t){return this.get("/relation/stats",{params:t})},this.getRelationWikiPages=function(t){return this.get("/relation/wiki_pages",{params:t})},this.getRelationsAll=function(t){return this.get("/relations/all",{params:t})},this.getSearchByKeyAndValue=function(t){return this.get("/search/by_key_and_value",{params:t})},this.getSearchByKeyword=function(t){return this.get("/search/by_keyword",{params:t})},this.getSearchByRole=function(t){return this.get("/search/by_role",{params:t})},this.getSearchByValue=function(t){return this.get("/search/by_value",{params:t})},this.getSiteInfo=function(t){return this.get("/site/info",{params:t})},this.getSiteSources=function(t){return this.get("/site/sources",{params:t})},this.getTagCombinations=function(t){return this.get("/tag/combinations",{params:t})},this.getTagDistributionNodes=function(t){return this.get("/tag/distribution/nodes",{params:t})},this.getTagDistributionWays=function(t){return this.get("/tag/distribution/ways",{params:t})},this.getTagStats=function(t){return this.get("/tag/stats",{params:t})},this.getTagWikiPages=function(t){return this.get("/tag/wiki_pages",{params:t})},this.getTagsPopular=function(t){return this.get("/tags/popular",{params:t})},this.getWikiLanguages=function(t){return this.get("/wiki/languages",{params:t})}}Object.defineProperty(e,"__esModule",{value:!0}),i.$inject=["$http","$q"],e["default"]=i}})}); |
@@ -85,3 +85,3 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
var osmSettingsModule = angular.module('osm.settings', [ngStorageModuleName]).factory('osmSettingsService', _settings2.default); | ||
var osmSettingsModule = angular.module('osm.settings', [ngStorageModuleName]).service('osmSettingsService', _settings2.default); | ||
@@ -100,3 +100,2 @@ exports.default = osmSettingsModule; | ||
/** | ||
@@ -110,70 +109,39 @@ * @ngdoc service | ||
function osmSettingsService($localStorage) { | ||
return { | ||
localStorage: $localStorage.$default({ | ||
userName: '', | ||
userID: '', | ||
credentials: '', | ||
nodes: [], | ||
changeset: '', | ||
osmAPI: '', | ||
overpassAPI: '' | ||
}), | ||
getUserName: function getUserName() { | ||
return this.localStorage.userName; | ||
}, | ||
setUserName: function setUserName(username) { | ||
this.localStorage.userName = username; | ||
}, | ||
getUserID: function getUserID() { | ||
return this.localStorage.userID; | ||
}, | ||
setUserID: function setUserID(userid) { | ||
this.localStorage.userID = userid; | ||
}, | ||
getCredentials: function getCredentials() { | ||
return this.localStorage.credentials; | ||
}, | ||
setCredentials: function setCredentials(credentials) { | ||
this.localStorage.credentials = credentials; | ||
}, | ||
getOSMAPI: function getOSMAPI() { | ||
if (this.localStorage.osmAPI) { | ||
return this.localStorage.osmAPI; | ||
} else { | ||
return 'http://api.openstreetmap.org/api'; | ||
} | ||
}, | ||
setOSMAPI: function setOSMAPI(osmAPI) { | ||
this.localStorage.osmAPI = osmAPI; | ||
}, | ||
getOverpassAPI: function getOverpassAPI() { | ||
if (this.localStorage.overpassAPI) { | ||
return this.localStorage.overpassAPI; | ||
} else { | ||
//return 'http://api.openstreetmap.org/api'; | ||
return 'http://overpass-api.de/api/interpreter'; | ||
} | ||
}, | ||
setOverpassAPI: function setOverpassAPI(overpassAPI) { | ||
this.localStorage.overpassAPI = overpassAPI; | ||
}, | ||
getNodes: function getNodes() { | ||
return this.localStorage.nodes; | ||
}, | ||
setNodes: function setNodes(nodes) { | ||
this.localStorage.nodes = nodes; | ||
}, | ||
getChangeset: function getChangeset() { | ||
return this.localStorage.changeset; | ||
}, | ||
setChangeset: function setChangeset(changeset) { | ||
this.localStorage.changeset = changeset; | ||
}, | ||
getOsmAuth: function getOsmAuth() { | ||
return this.localStorage.osmAuth; | ||
}, | ||
setOsmAuth: function setOsmAuth(options) { | ||
return this.localStorage.osmAuth = options; | ||
} | ||
this.localStorage = $localStorage.$default({ | ||
userName: '', | ||
userID: '', | ||
credentials: '', | ||
changeset: '' | ||
}); | ||
this.getUserName = function () { | ||
return this.localStorage.userName; | ||
}; | ||
this.setUserName = function (username) { | ||
this.localStorage.userName = username; | ||
}; | ||
this.getUserID = function () { | ||
return this.localStorage.userID; | ||
}; | ||
this.setUserID = function (userid) { | ||
this.localStorage.userID = userid; | ||
}; | ||
this.getCredentials = function () { | ||
return this.localStorage.credentials; | ||
}; | ||
this.setCredentials = function (credentials) { | ||
this.localStorage.credentials = credentials; | ||
}; | ||
this.getChangeset = function () { | ||
return this.localStorage.changeset; | ||
}; | ||
this.setChangeset = function (changeset) { | ||
this.localStorage.changeset = changeset; | ||
}; | ||
this.getOsmAuth = function () { | ||
return this.localStorage.osmAuth; | ||
}; | ||
this.setOsmAuth = function (options) { | ||
this.localStorage.osmAuth = options; | ||
}; | ||
} | ||
@@ -207,5 +175,9 @@ | ||
var _x2js = __webpack_require__(9); | ||
var _x2js2 = _interopRequireDefault(_x2js); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var osmUtilsModule = angular.module('osm.utils', [_settings2.default.name]).service('osmUtilsService', _utils2.default); | ||
var osmUtilsModule = angular.module('osm.utils', [_settings2.default.name, _x2js2.default.name]).service('osmUtilsService', _utils2.default); | ||
@@ -227,116 +199,13 @@ exports.default = osmUtilsModule; | ||
*/ | ||
function osmUtilsService(osmSettingsService) { | ||
var _this = this; | ||
function osmUtilsService($http, osmSettingsService, osmx2js) { | ||
this.serializer = new XMLSerializer(); | ||
if (typeof window.DOMParser !== 'undefined') { | ||
(function () { | ||
var parser = new window.DOMParser(); | ||
_this.parseXml = function parseXml(xmlStr) { | ||
return parser.parseFromString(xmlStr, 'application/xml'); | ||
}; | ||
})(); | ||
} else if (typeof window.ActiveXObject !== 'undefined') { | ||
this.parseXml = function parseXml(xmlStr) { | ||
var xmlDoc = new window.ActiveXObject('Microsoft.XMLDOM'); | ||
xmlDoc.async = 'false'; | ||
xmlDoc.loadXML(xmlStr); | ||
return xmlDoc; | ||
}; | ||
} else { | ||
throw new Error('No XML parser found'); | ||
} | ||
/** | ||
* @ngdoc method | ||
* @name createNodeXML | ||
* @name relationToGeoJSON | ||
* @methodOf osm.utils.osmUtilsService | ||
* @param {Object} node geojson | ||
* @return {string} XML | ||
* <osm> | ||
<node changeset="12" lat="..." lon="..."> | ||
<tag k="note" v="Just a node"/> | ||
... | ||
</node> | ||
</osm> | ||
*/ | ||
this.createNodeXML = function (node) { | ||
var newNode = '<osm><node changeset="CHANGESET" lat="LAT" lon="LNG">TAGS</node></osm>'; | ||
var tagTPL = '<tag k="KEY" v="VALUE"/>'; | ||
var tags = ''; | ||
var value; | ||
newNode = newNode.replace('CHANGESET', osmSettingsService.getChangeset()); | ||
for (var property in node.tags) { | ||
if (node.tags.hasOwnProperty(property)) { | ||
value = node.tags[property]; | ||
if (value === undefined || value === null) { | ||
continue; | ||
} else { | ||
tags += tagTPL.replace('KEY', property).replace('VALUE', node.tags[property]); | ||
} | ||
} | ||
} | ||
newNode = newNode.replace('TAGS', tags); | ||
newNode = newNode.replace('LNG', node.lng); | ||
newNode = newNode.replace('LAT', node.lat); | ||
return newNode; | ||
}; | ||
/** | ||
* @ngdoc method | ||
* @name serialiseXmlToString | ||
* @methodOf osm.utils.osmUtilsService | ||
* @param {Object} xml document object | ||
* @return {string} XML | ||
*/ | ||
this.serialiseXmlToString = function (xml) { | ||
return this.serializer.serializeToString(xml); | ||
}; | ||
/** | ||
* @ngdoc method | ||
* @name getTagsFromChildren | ||
* @methodOf osm.utils.osmUtilsService | ||
* @param {Object} element document element object | ||
* @return {Object} tags {k1:v1,k2: v2} | ||
*/ | ||
this.getTagsFromChildren = function (element) { | ||
var children, tags; | ||
tags = {}; | ||
for (var i = 0; i < element.children.length; i++) { | ||
children = element.children[i]; | ||
if (children.tagName !== 'tag') { | ||
continue; | ||
} | ||
tags[children.getAttribute('k')] = children.getAttribute('v'); | ||
} | ||
return tags; | ||
}; | ||
/** | ||
* @ngdoc method | ||
* @name getNameFromTags | ||
* @methodOf osm.utils.osmUtilsService | ||
* @param {Object} element document element object | ||
* @return {string} name value | ||
*/ | ||
this.getNameFromTags = function (element) { | ||
var children; | ||
for (var i = 0; i < element.children.length; i++) { | ||
children = element.children[i]; | ||
if (children.tagName !== 'tag') { | ||
continue; | ||
} | ||
if (children.getAttribute('k') === 'name') { | ||
return children.getAttribute('v'); | ||
} | ||
} | ||
}; | ||
/** | ||
* @ngdoc method | ||
* @name relationXmlToGeoJSON | ||
* @methodOf osm.utils.osmUtilsService | ||
* @param {Number} relationId id of the relation | ||
* @param {Object} relationXML document element object | ||
* @param {Object} relation json object | ||
* @return {Object} geojson | ||
*/ | ||
this.relationXmlToGeoJSON = function (relationID, relationXML) { | ||
this.relationToGeoJSON = function (relationID, relation) { | ||
var self = this; | ||
@@ -600,17 +469,9 @@ var features = []; | ||
}; | ||
/** | ||
* @ngdoc method | ||
* @name getNodesInJSON | ||
* @methodOf osm.utils.osmUtilsService | ||
* @param {Object} relationGeoJSON geojson | ||
* @return {Object} relation as geojson sorted | ||
*/ | ||
this.getNodesInJSON = function (xmlNodes, flatProperties) { | ||
osmSettingsService.setNodes(xmlNodes); | ||
var options = {}; | ||
if (flatProperties !== undefined) { | ||
options.flatProperties = flatProperties; | ||
} | ||
return osmtogeojson(xmlNodes, options); | ||
this.x2js = osmx2js; | ||
this.xml2js = function (xml_str) { | ||
return osmx2js.xml2js(xml_str); | ||
}; | ||
this.js2xml = function (json) { | ||
return osmx2js.js2xml(json); | ||
}; | ||
/** | ||
@@ -664,2 +525,21 @@ * @ngdoc method | ||
/***/ }, | ||
/* 9 */ | ||
/***/ function(module, exports) { | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
//https://github.com/abdmob/x2js as angular service | ||
var osmx2jsModule = angular.module('osm.x2js', []).provider('osmx2js', function osmx2jsProvider() { | ||
this.options = {}; | ||
this.$get = function osmx2jsFactory() { | ||
return new X2JS(this.options); //X2JS must be global | ||
}; | ||
}); | ||
exports.default = osmx2jsModule; | ||
/***/ } | ||
@@ -666,0 +546,0 @@ /******/ ]) |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("ngstorage")):"function"==typeof define&&define.amd?define(["ngstorage"],t):"object"==typeof exports?exports.name=t(require("ngstorage")):(e["angular-osm"]=e["angular-osm"]||{},e["angular-osm"].name=t(e.ngstorage))}(this,function(e){return function(e){function t(o){if(r[o])return r[o].exports;var n=r[o]={exports:{},id:o,loaded:!1};return e[o].call(n.exports,n,n.exports,t),n.loaded=!0,n.exports}var r={};return t.m=e,t.c=r,t.p="",t(0)}([function(e,t,r){e.exports=r(7)},,,,function(e,t,r){"use strict";function o(e){return e&&e.__esModule?e:{"default":e}}Object.defineProperty(t,"__esModule",{value:!0});var n=r(5),i=o(n),s=r(6),a=o(s),l=a["default"]?a["default"].name:"ngStorage",u=angular.module("osm.settings",[l]).factory("osmSettingsService",i["default"]);t["default"]=u},function(e,t){"use strict";function r(e){return{localStorage:e.$default({userName:"",userID:"",credentials:"",nodes:[],changeset:"",osmAPI:"",overpassAPI:""}),getUserName:function(){return this.localStorage.userName},setUserName:function(e){this.localStorage.userName=e},getUserID:function(){return this.localStorage.userID},setUserID:function(e){this.localStorage.userID=e},getCredentials:function(){return this.localStorage.credentials},setCredentials:function(e){this.localStorage.credentials=e},getOSMAPI:function(){return this.localStorage.osmAPI?this.localStorage.osmAPI:"http://api.openstreetmap.org/api"},setOSMAPI:function(e){this.localStorage.osmAPI=e},getOverpassAPI:function(){return this.localStorage.overpassAPI?this.localStorage.overpassAPI:"http://overpass-api.de/api/interpreter"},setOverpassAPI:function(e){this.localStorage.overpassAPI=e},getNodes:function(){return this.localStorage.nodes},setNodes:function(e){this.localStorage.nodes=e},getChangeset:function(){return this.localStorage.changeset},setChangeset:function(e){this.localStorage.changeset=e},getOsmAuth:function(){return this.localStorage.osmAuth},setOsmAuth:function(e){return this.localStorage.osmAuth=e}}}Object.defineProperty(t,"__esModule",{value:!0}),r.$inject=["$localStorage"],t["default"]=r},function(t,r){t.exports=e},function(e,t,r){"use strict";function o(e){return e&&e.__esModule?e:{"default":e}}Object.defineProperty(t,"__esModule",{value:!0});var n=r(8),i=o(n),s=r(4),a=o(s),l=angular.module("osm.utils",[a["default"].name]).service("osmUtilsService",i["default"]);t["default"]=l},function(e,t){"use strict";function r(e){var t=this;if(this.serializer=new XMLSerializer,"undefined"!=typeof window.DOMParser)!function(){var e=new window.DOMParser;t.parseXml=function(t){return e.parseFromString(t,"application/xml")}}();else{if("undefined"==typeof window.ActiveXObject)throw new Error("No XML parser found");this.parseXml=function(e){var t=new window.ActiveXObject("Microsoft.XMLDOM");return t.async="false",t.loadXML(e),t}}this.createNodeXML=function(t){var r,o='<osm><node changeset="CHANGESET" lat="LAT" lon="LNG">TAGS</node></osm>',n='<tag k="KEY" v="VALUE"/>',i="";o=o.replace("CHANGESET",e.getChangeset());for(var s in t.tags)if(t.tags.hasOwnProperty(s)){if(r=t.tags[s],void 0===r||null===r)continue;i+=n.replace("KEY",s).replace("VALUE",t.tags[s])}return o=o.replace("TAGS",i),o=o.replace("LNG",t.lng),o=o.replace("LAT",t.lat)},this.serialiseXmlToString=function(e){return this.serializer.serializeToString(e)},this.getTagsFromChildren=function(e){var t,r;r={};for(var o=0;o<e.children.length;o++)t=e.children[o],"tag"===t.tagName&&(r[t.getAttribute("k")]=t.getAttribute("v"));return r},this.getNameFromTags=function(e){for(var t,r=0;r<e.children.length;r++)if(t=e.children[r],"tag"===t.tagName&&"name"===t.getAttribute("k"))return t.getAttribute("v")},this.relationXmlToGeoJSON=function(e,t){var r=this,o=[],n=[],i={type:"FeatureCollection",properties:{id:e},options:{},members:[],features:o,relations:n},s=t.getElementById(e);i.properties.visible=s.getAttribute("visible"),i.properties.version=s.getAttribute("version"),i.properties.changeset=s.getAttribute("changeset"),i.properties.timestamp=s.getAttribute("timestamp"),i.properties.user=s.getAttribute("user"),i.properties.uid=s.getAttribute("uid");var a,l,u,g,c,f,p,d,m;for(l=0;l<s.children.length;l++)if(a=s.children[l],"member"===a.tagName)if(d={type:a.getAttribute("type"),ref:a.getAttribute("ref"),role:a.getAttribute("role")},i.members.push(d),m=t.getElementById(a.getAttribute("ref")),c=r.getTagsFromChildren(m),d.name=c.name,"way"===m.tagName){f=[],p={type:"Feature",properties:c,id:a.getAttribute("ref"),geometry:{type:"LineString",coordinates:f}};for(var h=0;h<m.children.length;h++)u=m.children[h],"nd"===u.tagName&&(g=t.getElementById(u.getAttribute("ref")),f.push([parseFloat(g.getAttribute("lon")),parseFloat(g.getAttribute("lat"))]));o.push(p)}else"node"===m.tagName?(p={type:"Feature",properties:c,id:a.getAttribute("ref"),geometry:{type:"Point",coordinates:[parseFloat(m.getAttribute("lon")),parseFloat(m.getAttribute("lat"))]}},o.push(p)):"relation"===m.tagName&&(d.tags=c);return i.tags=r.getTagsFromChildren(s),i},this.encodeXML=function(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")},this.relationGeoJSONToXml=function(t){var r,o=t.properties,n=t.members,i=e,s='<?xml version="1.0" encoding="UTF-8"?>\n';for(s+='<osm version="0.6" generator="angular-osm 0.2" copyright="OpenStreetMap and contributors" attribution="http://www.openstreetmap.org/copyright" license="http://opendatacommons.org/licenses/odbl/1-0/">\n',s+=' <relation id="'+o.id+'" visible="'+o.visible+'" ',s+='version="'+o.version+'" ',s+='changeset="'+i.getChangeset()+'" timestamp="'+(new Date).toISOString()+'" ',s+='user="'+i.getUserName()+'" uid="'+o.uid+'">\n',r=0;r<n.length;r++)s+=' <member type="'+n[r].type+'" ',s+='ref="'+n[r].ref,s+="relation"===n[r].type?'" role="'+n[r].role+'"/>\n':'" role="'+n[r].role+'"/>\n';var a=t.tags;for(var l in a)s+=' <tag k="'+l+'" v="'+this.encodeXML(a[l])+'"/>\n';return s+=" </relation>\n",s+="</osm>"},this.sortRelationMembers=function(e){var t,r,o,n,i,s,a,l,u,g,c,f,p=e.members,d=e.features,m=[],h=function(e){m.splice(0,0,e)},v=function(e){m.push(e)},y=function(e){return d[e].geometry.coordinates},A=!1;for(r=0;r<p.length;r++)if(o=p[r],"way"===o.type){for(c=!1,i=0;i<m.length;i++)m[i].ref===o.ref&&(c=!0);if(!c){for(0===m.length&&(m.push(o),l=y(r),u=l[0],g=l[l.length-1]),f=A=!1,n=0;n<d.length;n++)if(t=d[n],"LineString"===t.geometry.type){for(c=!1,i=0;i<m.length;i++)m[i].ref===t.id&&(c=!0);c||(l=y(n),s=l[0],a=l[l.length-1],u[0]!==a[0]||u[1]!==a[1]?g[0]!==s[0]||g[1]!==s[1]?u[0]!==s[0]||u[1]!==s[1]?g[0]!==a[0]||g[1]!==a[1]||(v(p[n]),g=s,A=!0):(h(p[n]),u=a,f=!0):(v(p[n]),g=a,A=!0):(h(p[n]),u=s,f=!0))}f||A||(console.log("not found connected ways for "+o.ref),console.log(u),console.log(g))}}else m.push(o);if(p.length===m.length){e.members=m;var b={loaded:!1},S=function(e){if(!b.loaded)for(var t=0;t<d.length;t++)b[d[t].id]=d[t];return b[e]};e.features=[];for(var N=0;N<m.length;N++)e.features.push(S(m[N].ref))}else console.error("can t sort this relation");return e},this.getNodesInJSON=function(t,r){e.setNodes(t);var o={};return void 0!==r&&(o.flatProperties=r),osmtogeojson(t,o)},this.yqlJSON=function(e){var t,r,o=$q.defer();return r={params:{q:"select * from json where url='"+e+"';",format:"json"}},t="http://query.yahooapis.com/v1/public/yql",$http.get(t,r).then(function(e){null===e.data.query.results?o.resolve([]):o.resolve(e.data.query.results.json)},function(e){o.reject(e)}),o.promise},this.getElementTypeFromFeature=function(e){var t=e.geometry.type;return"LineString"===t?"way":"Point"===t?"node":void console.error("not supported type "+t)}}Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=r}])}); | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("ngstorage")):"function"==typeof define&&define.amd?define(["ngstorage"],t):"object"==typeof exports?exports.name=t(require("ngstorage")):(e["angular-osm"]=e["angular-osm"]||{},e["angular-osm"].name=t(e.ngstorage))}(this,function(e){return function(e){function t(o){if(r[o])return r[o].exports;var n=r[o]={exports:{},id:o,loaded:!1};return e[o].call(n.exports,n,n.exports,t),n.loaded=!0,n.exports}var r={};return t.m=e,t.c=r,t.p="",t(0)}([function(e,t,r){e.exports=r(7)},,,,function(e,t,r){"use strict";function o(e){return e&&e.__esModule?e:{"default":e}}Object.defineProperty(t,"__esModule",{value:!0});var n=r(5),s=o(n),i=r(6),a=o(i),u=a["default"]?a["default"].name:"ngStorage",l=angular.module("osm.settings",[u]).service("osmSettingsService",s["default"]);t["default"]=l},function(e,t){"use strict";function r(e){this.localStorage=e.$default({userName:"",userID:"",credentials:"",changeset:""}),this.getUserName=function(){return this.localStorage.userName},this.setUserName=function(e){this.localStorage.userName=e},this.getUserID=function(){return this.localStorage.userID},this.setUserID=function(e){this.localStorage.userID=e},this.getCredentials=function(){return this.localStorage.credentials},this.setCredentials=function(e){this.localStorage.credentials=e},this.getChangeset=function(){return this.localStorage.changeset},this.setChangeset=function(e){this.localStorage.changeset=e},this.getOsmAuth=function(){return this.localStorage.osmAuth},this.setOsmAuth=function(e){this.localStorage.osmAuth=e}}Object.defineProperty(t,"__esModule",{value:!0}),r.$inject=["$localStorage"],t["default"]=r},function(t,r){t.exports=e},function(e,t,r){"use strict";function o(e){return e&&e.__esModule?e:{"default":e}}Object.defineProperty(t,"__esModule",{value:!0});var n=r(8),s=o(n),i=r(4),a=o(i),u=r(9),l=o(u),g=angular.module("osm.utils",[a["default"].name,l["default"].name]).service("osmUtilsService",s["default"]);t["default"]=g},function(e,t){"use strict";function r(e,t,r){this.relationToGeoJSON=function(e,t){var r=this,o=[],n=[],s={type:"FeatureCollection",properties:{id:e},options:{},members:[],features:o,relations:n},t=relationXML.getElementById(e);s.properties.visible=t.getAttribute("visible"),s.properties.version=t.getAttribute("version"),s.properties.changeset=t.getAttribute("changeset"),s.properties.timestamp=t.getAttribute("timestamp"),s.properties.user=t.getAttribute("user"),s.properties.uid=t.getAttribute("uid");var i,a,u,l,g,c,f,p,d;for(a=0;a<t.children.length;a++)if(i=t.children[a],"member"===i.tagName)if(p={type:i.getAttribute("type"),ref:i.getAttribute("ref"),role:i.getAttribute("role")},s.members.push(p),d=relationXML.getElementById(i.getAttribute("ref")),g=r.getTagsFromChildren(d),p.name=g.name,"way"===d.tagName){c=[],f={type:"Feature",properties:g,id:i.getAttribute("ref"),geometry:{type:"LineString",coordinates:c}};for(var m=0;m<d.children.length;m++)u=d.children[m],"nd"===u.tagName&&(l=relationXML.getElementById(u.getAttribute("ref")),c.push([parseFloat(l.getAttribute("lon")),parseFloat(l.getAttribute("lat"))]));o.push(f)}else"node"===d.tagName?(f={type:"Feature",properties:g,id:i.getAttribute("ref"),geometry:{type:"Point",coordinates:[parseFloat(d.getAttribute("lon")),parseFloat(d.getAttribute("lat"))]}},o.push(f)):"relation"===d.tagName&&(p.tags=g);return s.tags=r.getTagsFromChildren(t),s},this.encodeXML=function(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")},this.relationGeoJSONToXml=function(e){var r,o=e.properties,n=e.members,s=t,i='<?xml version="1.0" encoding="UTF-8"?>\n';for(i+='<osm version="0.6" generator="angular-osm 0.2" copyright="OpenStreetMap and contributors" attribution="http://www.openstreetmap.org/copyright" license="http://opendatacommons.org/licenses/odbl/1-0/">\n',i+=' <relation id="'+o.id+'" visible="'+o.visible+'" ',i+='version="'+o.version+'" ',i+='changeset="'+s.getChangeset()+'" timestamp="'+(new Date).toISOString()+'" ',i+='user="'+s.getUserName()+'" uid="'+o.uid+'">\n',r=0;r<n.length;r++)i+=' <member type="'+n[r].type+'" ',i+='ref="'+n[r].ref,i+="relation"===n[r].type?'" role="'+n[r].role+'"/>\n':'" role="'+n[r].role+'"/>\n';var a=e.tags;for(var u in a)i+=' <tag k="'+u+'" v="'+this.encodeXML(a[u])+'"/>\n';return i+=" </relation>\n",i+="</osm>"},this.sortRelationMembers=function(e){var t,r,o,n,s,i,a,u,l,g,c,f,p=e.members,d=e.features,m=[],h=function(e){m.splice(0,0,e)},y=function(e){m.push(e)},v=function(e){return d[e].geometry.coordinates},b=!1;for(r=0;r<p.length;r++)if(o=p[r],"way"===o.type){for(c=!1,s=0;s<m.length;s++)m[s].ref===o.ref&&(c=!0);if(!c){for(0===m.length&&(m.push(o),u=v(r),l=u[0],g=u[u.length-1]),f=b=!1,n=0;n<d.length;n++)if(t=d[n],"LineString"===t.geometry.type){for(c=!1,s=0;s<m.length;s++)m[s].ref===t.id&&(c=!0);c||(u=v(n),i=u[0],a=u[u.length-1],l[0]!==a[0]||l[1]!==a[1]?g[0]!==i[0]||g[1]!==i[1]?l[0]!==i[0]||l[1]!==i[1]?g[0]!==a[0]||g[1]!==a[1]||(y(p[n]),g=i,b=!0):(h(p[n]),l=a,f=!0):(y(p[n]),g=a,b=!0):(h(p[n]),l=i,f=!0))}f||b||(console.log("not found connected ways for "+o.ref),console.log(l),console.log(g))}}else m.push(o);if(p.length===m.length){e.members=m;var S={loaded:!1},A=function(e){if(!S.loaded)for(var t=0;t<d.length;t++)S[d[t].id]=d[t];return S[e]};e.features=[];for(var j=0;j<m.length;j++)e.features.push(A(m[j].ref))}else console.error("can t sort this relation");return e},this.x2js=r,this.xml2js=function(e){return r.xml2js(e)},this.js2xml=function(e){return r.js2xml(e)},this.yqlJSON=function(t){var r,o,n=$q.defer();return o={params:{q:"select * from json where url='"+t+"';",format:"json"}},r="http://query.yahooapis.com/v1/public/yql",e.get(r,o).then(function(e){null===e.data.query.results?n.resolve([]):n.resolve(e.data.query.results.json)},function(e){n.reject(e)}),n.promise},this.getElementTypeFromFeature=function(e){var t=e.geometry.type;return"LineString"===t?"way":"Point"===t?"node":void console.error("not supported type "+t)}}Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=r},function(e,t){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=angular.module("osm.x2js",[]).provider("osmx2js",function(){this.options={},this.$get=function(){return new X2JS(this.options)}});t["default"]=r}])}); |
{ | ||
"name": "angular-osm", | ||
"version": "0.0.1", | ||
"description": "OpenStreetMap APIs as services for angular", | ||
@@ -15,3 +14,5 @@ "main": "dist/osm-full.js", | ||
"gh-pages": "rm -rf gh-pages/dist && webpack && mv dist gh-pages/", | ||
"prepublish": "webpack && webpack --config webpack.config.min.js" | ||
"prepublish": "webpack && webpack --config webpack.config.min.js", | ||
"coveralls": "npm run test && ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage", | ||
"semantic-release": "semantic-release pre && npm publish && semantic-release post" | ||
}, | ||
@@ -26,2 +27,3 @@ "author": "Jean-Michel FRANCOIS <toutpt@gmail.com>", | ||
"babel-preset-es2015": "^6.6.0", | ||
"coveralls": "^2.11.9", | ||
"jasmine-core": "^2.4.1", | ||
@@ -36,3 +38,4 @@ "karma": "^0.13.22", | ||
"phantomjs-prebuilt": "^2.1.3", | ||
"webpack": "^1.13.0" | ||
"webpack": "^1.13.0", | ||
"semantic-release": "^4.3.5" | ||
}, | ||
@@ -44,4 +47,5 @@ "dependencies": { | ||
"osm-auth": "0.2.8", | ||
"osmtogeojson": "https://github.com/tyrasd/osmtogeojson.git#2.2.11" | ||
} | ||
} | ||
"x2js": "^2.0.1" | ||
}, | ||
"version": "0.0.2" | ||
} |
Angular OSM | ||
=========== | ||
[](https://travis-ci.org/toutpt/angular-osm) [](https://david-dm.org/toutpt/angular-osm) | ||
[![NPM][npm-icon] ][npm-url] | ||
[![Travis CI][travis-ci-image] ][travis-ci-url] | ||
[![Codacy Badge][codacy-image] ][codacy-url] | ||
[![semantic-release][semantic-image] ][semantic-url] | ||
[![Quality][quality-badge] ][quality-url] | ||
[![Coverage Status][coverage-image] ][coverage-url] | ||
[![Circle CI] [circle-icon] ][circle-url] | ||
[![dependencies][dependencies-image] ][dependencies-url] | ||
[![devdependencies][devdependencies-image] ][devdependencies-url] | ||
[npm-icon]: https://nodei.co/npm/angular-osm.png?downloads=true | ||
[npm-url]: https://npmjs.org/package/angular-osm | ||
[travis-ci-image]: https://travis-ci.org/toutpt/angular-osm.png?branch=master | ||
[travis-ci-url]: https://travis-ci.org/toutpt/travis-ci | ||
[coverage-image]: https://coveralls.io/repos/toutpt/angular-osm/badge.png | ||
[coverage-url]: https://coveralls.io/r/toutpt/angular-osm | ||
[dependencies-image]: https://david-dm.org/toutpt/angular-osm.png | ||
[dependencies-url]: https://david-dm.org/toutpt/angular-osm | ||
[devdependencies-image]: https://david-dm.org/toutpt/angular-osm/dev-status.png | ||
[devdependencies-url]: https://david-dm.org/toutpt/angular-osm#info=devDependencies | ||
[codacy-image]: https://api.codacy.com/project/badge/Grade/aa28c31e62114c2591e7a7e3161d48ca | ||
[codacy-url]: https://www.codacy.com/public/toutpt/angular-osm.git | ||
[semantic-image]: https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg | ||
[semantic-url]: https://github.com/semantic-release/semantic-release | ||
[quality-badge]: http://npm.packagequality.com/shield/angular-osm.svg | ||
[quality-url]: http://packagequality.com/#?package=angular-osm | ||
[circle-icon]: https://circleci.com/gh/toutpt/angular-osm.svg?style=svg | ||
[circle-url]: https://circleci.com/gh/toutpt/angular-osm | ||
Angular OSM is a set of angular services which provides API to use OSM APIs. | ||
For more information please check the website : http://toutpt.github.io/angular-osm |
@@ -13,4 +13,13 @@ import base64 from 'angular-base64'; | ||
]) | ||
.service('osmAPI', osmAPI); | ||
.service('osmAPI', osmAPI) | ||
.provider('osmAPI', function osmAPIProvider () { | ||
this.options = { | ||
url: 'http://api.openstreetmap.org/api' | ||
}; | ||
this.$get = function osmAPIFactory($base64, $http, $q, osmSettingsService, osmUtilsService) { | ||
return new osmAPI($base64, $http, $q, osmSettingsService, osmUtilsService, this.options); | ||
}; | ||
this.$get.$inject = ['$base64', '$http', '$q', 'osmSettingsService', 'osmUtilsService']; | ||
}); | ||
export default osmAPIModule; |
/** | ||
* @ngdoc service | ||
* @name osm.oauth.osmAuthService | ||
* @description The main idea is use geojson object where it is possible | ||
* for the rest of the API (changeset, ...) it's XML2JS that is used so always expect objects. | ||
* @param {any} $base64 | ||
@@ -9,4 +11,7 @@ * @param {any} $http | ||
*/ | ||
osmAPI.$inject = ['$base64', '$http', '$q', 'osmSettingsService', 'osmUtilsService']; | ||
function osmAPI($base64, $http, $q, osmSettingsService, osmUtilsService) { | ||
function osmAPI($base64, $http, $q, osmSettingsService, osmUtilsService, options) { | ||
this.url = options.url; | ||
// ------------------ CREDENTIALS ----------------- | ||
/** | ||
@@ -20,12 +25,10 @@ * @ngdoc method | ||
*/ | ||
this.validateCredentials = function (){ | ||
this.validateCredentials = function () { | ||
var deferred = $q.defer(); | ||
this.getUserDetails().then(function(data){ | ||
var parsed = osmUtilsService.parseXml(data); | ||
var users = parsed.getElementsByTagName('user'); | ||
if (users.length === 1){ | ||
osmSettingsService.setUserID(users[0].id); | ||
this.getUserDetails().then(function (data) { | ||
if (data.osm.user) { | ||
osmSettingsService.setUserID(data.osm.user._id); | ||
} | ||
deferred.resolve(users.length > 0); | ||
}, function(error){ | ||
deferred.resolve(data.osm.user !== undefined); | ||
}, function (error) { | ||
deferred.reject(error); | ||
@@ -43,3 +46,3 @@ }); | ||
*/ | ||
this.setCredentials = function(username, password){ | ||
this.setCredentials = function (username, password) { | ||
osmSettingsService.setUserName(username); | ||
@@ -58,3 +61,3 @@ var credentials = $base64.encode(username + ':' + password); | ||
*/ | ||
this.getCredentials = function(){ | ||
this.getCredentials = function () { | ||
return osmSettingsService.getCredentials(); | ||
@@ -69,3 +72,3 @@ }; | ||
*/ | ||
this.getAuthorization = function(){ | ||
this.getAuthorization = function () { | ||
return 'Basic ' + osmSettingsService.getCredentials(); | ||
@@ -83,4 +86,106 @@ }; | ||
}; | ||
/** | ||
* @ngdoc method | ||
* @name setOauth | ||
* @description use oauth object to call API | ||
* @methodOf osm.api.osmAPI | ||
*/ | ||
this.setOauth = function setOauth(oauth) { | ||
this._oauth = oauth; | ||
}; | ||
/** | ||
* @ngdoc method | ||
* @name setOauth | ||
* @description use oauth object to call API | ||
* @methodOf osm.api.osmAPI | ||
* @return {Object} oauth | ||
*/ | ||
this.getOauth = function getOauth() { | ||
return this._oauth; | ||
}; | ||
// ------------------ INTERNAL CALL SERVER (API) ----------------- | ||
function isElement(obj) { | ||
try { | ||
//Using W3 DOM2 (works for FF, Opera and Chrom) | ||
return obj instanceof HTMLElement; | ||
} | ||
catch(e){ | ||
//Browsers not supporting W3 DOM2 don't have HTMLElement and | ||
//an exception is thrown and we end up here. Testing some | ||
//properties that all elements have. (works on IE7) | ||
return (typeof obj==="object") && | ||
(obj.nodeType===1) && (typeof obj.style === "object") && | ||
(typeof obj.ownerDocument ==="object"); | ||
} | ||
} | ||
/** | ||
* @ngdoc method | ||
* @name xhr | ||
* @description call the API | ||
* @param {Object} options | ||
* @comment | ||
* ``` | ||
var options = { | ||
method: 'GET', // POST, DELETE, PUT | ||
path: '/0.6/changesets', //without the /api | ||
data: content //if you need a payload | ||
}; | ||
osmAPI.xhr(options); | ||
``` | ||
* @methodOf osm.api.osmAPI | ||
* @return {Object} oauth | ||
*/ | ||
this.xhr = function (options) { | ||
let deferred = $q.defer(); | ||
let promise; | ||
let hasOauth = this._oauth; | ||
if (hasOauth) { | ||
options.path = '/api' + options.path; | ||
if (options.data) { | ||
options.body = options.data; | ||
options.data = undefined; | ||
} | ||
promise = this._oauth.xhr(options); | ||
} else { | ||
options.url = this.url + options.path; | ||
options.headers = { | ||
Authorization: this.getAuthorization() | ||
}; | ||
promise = $http(options); | ||
} | ||
promise.then(function (data) { | ||
var d; | ||
var t = function (d) { | ||
if (!d) { | ||
return d; | ||
} | ||
if (d.substr) { | ||
if (d.substr(0, 5) === '<?xml') { | ||
return osmUtilsService.xml2js(d); | ||
} | ||
} else if (isElement(d)) { | ||
return osmUtilsService.x2js.dom2js(d); | ||
} | ||
return d; | ||
}; | ||
if (hasOauth) { | ||
d = data; | ||
} else { | ||
d = data.data; | ||
} | ||
deferred.resolve(t(d)); | ||
}, function (error) { | ||
deferred.reject(error); | ||
}); | ||
return deferred.promise; | ||
}; | ||
/** | ||
* @ngdoc method | ||
* @name getAuthenticated | ||
@@ -92,8 +197,10 @@ * @description send a get request to OSM with | ||
*/ | ||
this.getAuthenticated = function(method, config){ | ||
if (config === undefined){ | ||
config = {}; | ||
this.getAuthenticated = function (method, config) { | ||
var _config = angular.copy(config); | ||
if (!_config) { | ||
_config = {}; | ||
} | ||
config.headers = {Authorization: this.getAuthorization()}; | ||
return this.get(method, config); | ||
_config.method = 'GET'; | ||
_config.path = method; | ||
return this.xhr(_config); | ||
}; | ||
@@ -109,10 +216,10 @@ /** | ||
*/ | ||
this.get = function(method, config){ | ||
this.get = function (method, config) { | ||
var deferred = $q.defer(); | ||
var self = this; | ||
var url = osmSettingsService.getOSMAPI() + method; | ||
$http.get(url, config).then(function(data){ | ||
deferred.resolve(data.data); | ||
}, function(data) { | ||
deferred.reject(data); | ||
var url = this.url + method; | ||
$http.get(url, config).then(function (data) { | ||
deferred.resolve(osmUtilsService.xml2js(data.data)); | ||
}, function (error) { | ||
deferred.reject(error); | ||
}); | ||
@@ -131,17 +238,11 @@ return deferred.promise; | ||
*/ | ||
this.put = function(method, content, config){ | ||
var deferred = $q.defer(); | ||
var self = this; | ||
if (config === undefined){ | ||
this.put = function (method, content, config) { | ||
if (!config) { | ||
config = {}; | ||
} | ||
config.headers = {Authorization: this.getAuthorization()}; | ||
var url = osmSettingsService.getOSMAPI() + method; | ||
$http.put(url, content, config).then(function(data){ | ||
deferred.resolve(data.data); | ||
},function(data) { | ||
deferred.reject(data); | ||
}); | ||
return deferred.promise; | ||
var _config = angular.copy(config); | ||
_config.method = 'PUT'; | ||
_config.path = method; | ||
_config.data = osmUtilsService.js2xml(content); | ||
return this.xhr(_config); | ||
}; | ||
@@ -157,19 +258,16 @@ /** | ||
*/ | ||
this.delete = function(method, config){ | ||
var deferred = $q.defer(); | ||
var self = this; | ||
if (config === undefined){ | ||
this.delete = function (method, config) { | ||
if (!config) { | ||
config = {}; | ||
} | ||
config.headers = {Authorization: this.getAuthorization()}; | ||
config.url = osmSettingsService.getOSMAPI() + method; | ||
config.method = 'delete'; | ||
$http(config).then(function(data){ | ||
deferred.resolve(data.data); | ||
}, function(data) { | ||
deferred.reject(data); | ||
}); | ||
return deferred.promise; | ||
var _config = angular.copy(config); | ||
_config.method = 'DELETE'; | ||
_config.path = method; | ||
return this.xhr(_config); | ||
}; | ||
// ------------------ CHANGESET ----------------- | ||
/** | ||
@@ -182,7 +280,13 @@ * @ngdoc method | ||
*/ | ||
this.createChangeset = function(comment){ | ||
this.createChangeset = function (comment) { | ||
var deferred = $q.defer(); | ||
var changeset = '<osm><changeset><tag k="created_by" v="Angular-OSM"/><tag k="comment" v="'; | ||
changeset += comment + '"/></changeset></osm>'; | ||
this.put('/0.6/changeset/create', changeset).then(function(data){ | ||
var changeset = {osm: { | ||
changeset: { | ||
tag: [ | ||
{_k:'created_by', _v: 'Angular-OSM'}, | ||
{_k:'comment', _v: comment}, | ||
] | ||
} | ||
}}; | ||
this.put('/0.6/changeset/create', changeset).then(function (data) { | ||
osmSettingsService.setChangeset(data); | ||
@@ -200,3 +304,3 @@ deferred.resolve(data); | ||
*/ | ||
this.getLastOpenedChangesetId = function(){ | ||
this.getLastOpenedChangesetId = function () { | ||
var deferred = $q.defer(); | ||
@@ -206,9 +310,11 @@ var config = { | ||
}; | ||
this.get('/0.6/changesets', config).then(function(data){ | ||
var parsed = osmUtilsService.parseXml(data); | ||
var changesets = parsed.getElementsByTagName('changeset'); | ||
if (changesets.length > 0){ | ||
this.get('/0.6/changesets', config).then(function (data) { | ||
var changesets = data.osm.changeset; | ||
if (changesets.length > 0) { | ||
osmSettingsService.setChangeset(changesets[0].id); | ||
deferred.resolve(changesets[0].id); | ||
}else{ | ||
} else if (changesets._id) { | ||
osmSettingsService.setChangeset(changesets._id); | ||
deferred.resolve(changesets._id); | ||
} else { | ||
osmSettingsService.setChangeset(); | ||
@@ -227,3 +333,3 @@ deferred.resolve(); | ||
*/ | ||
this.closeChangeset = function(){ | ||
this.closeChangeset = function () { | ||
var changeset = osmSettingsService.getChangeset(); | ||
@@ -236,4 +342,21 @@ return this.put('/0.6/changeset/'+ changeset +'/close') | ||
}; | ||
// ------------------ USER API ----------------- | ||
/** | ||
* @ngdoc method | ||
* @name getUserById | ||
* @methodOf osm.api.osmAPI | ||
* @param {string} id of the user | ||
* @returns {Promise} $http.get response | ||
* /0.6/user/#id | ||
*/ | ||
this.getUserById = function (id) { | ||
return this.getAuthenticated('/0.6/user/' + id); | ||
}; | ||
/** | ||
* @ngdoc method | ||
* @name getUserDetails | ||
@@ -244,3 +367,3 @@ * @methodOf osm.api.osmAPI | ||
*/ | ||
this.getUserDetails = function(){ | ||
this.getUserDetails = function () { | ||
return this.getAuthenticated('/0.6/user/details'); | ||
@@ -250,2 +373,29 @@ }; | ||
* @ngdoc method | ||
* @name getUserPreferences | ||
* @methodOf osm.api.osmAPI | ||
* @returns {Promise} $http.get response | ||
* /0.6/user/preferences | ||
*/ | ||
this.getUserPreferences = function () { | ||
return this.getAuthenticated('/0.6/user/preferences'); | ||
}; | ||
/** | ||
* @ngdoc method | ||
* @name putUserPreferences | ||
* @methodOf osm.api.osmAPI | ||
* @param {string} key the preference key | ||
* @param {string} value the preference value | ||
* @returns {Promise} $http.get response | ||
* /0.6/user/preferences | ||
*/ | ||
this.putUserPreferences = function (key, value) { | ||
return this.put('/0.6/user/preferences/' + key , value); | ||
}; | ||
//------------------ MAP DATA ------------------------- | ||
/** | ||
* @ngdoc method | ||
* @name getMap | ||
@@ -262,3 +412,3 @@ * @methodOf osm.api.osmAPI | ||
*/ | ||
this.getMap = function(bbox){ | ||
this.getMap = function (bbox) { | ||
return this.get('/0.6/map?bbox=' + bbox); | ||
@@ -269,2 +419,22 @@ }; | ||
* @ngdoc method | ||
* @name getMapGeoJSON | ||
* @methodOf osm.api.osmAPI | ||
* @param {string} bbox the bounding box | ||
* @returns {Promise} $http.get response | ||
*/ | ||
this.getMapGeoJSON = function (bbox) { | ||
var self = this; | ||
var deferred = $q.defer(); | ||
self.getMap(bbox).then(function (nodes) { | ||
var geojsonNodes = osmUtilsService.js2geojson(nodes); | ||
deferred.resolve(geojsonNodes); | ||
}, function (error) { | ||
deferred.reject(error); | ||
}); | ||
return deferred.promise; | ||
}; | ||
/** | ||
* @ngdoc method | ||
* @name getNotes | ||
@@ -278,116 +448,157 @@ * @methodOf osm.api.osmAPI | ||
top is the latitude of the top (northernmost) side of the bounding box. | ||
* @param {string} format Currently the format rss, xml, json and gpx are supported. | ||
* @returns {Promise} $http.get response | ||
* /0.6/notes[.format]?bbox=bbox | ||
*/ | ||
this.getNotes = function (bbox, format) { | ||
var url = '/0.6/notes'; | ||
if (format) { | ||
url += '.' + format; | ||
} | ||
url += '?bbox=' + bbox; | ||
this.getNotes = function (bbox) { | ||
var url = '/0.6/notes?bbox=' + bbox; | ||
return this.get(url); | ||
}; | ||
//------------------ ELEMENTS: Node ---------------- | ||
/** | ||
* @ngdoc method | ||
* @name updateNode | ||
* @name createNode | ||
* @methodOf osm.api.osmAPI | ||
* @param {Object} currentNode geojson | ||
* @param {Object} updatedNode geojson | ||
* @param {Object/string} node | ||
var node = {osm: {node: { | ||
_changeset: '12', _lat: '...', _lon: '...', | ||
tags: [ | ||
{_k: '...', _v: '...'} | ||
] | ||
}}}; | ||
* @returns {Promise} $http.put response | ||
* PUT /0.6/node/create | ||
*/ | ||
this.createNode = function (node) { | ||
return this.put('/0.6/node/create', node); | ||
}; | ||
/** | ||
* @ngdoc method | ||
* @name getNode | ||
* @methodOf osm.api.osmAPI | ||
* @param {string} id | ||
* @returns {Promise} $http.get response | ||
* /0.6/map?bbox=bbox | ||
* GET /0.6/node/#id | ||
*/ | ||
this.updateNode = function(currentNode, updatedNode){ | ||
//we need to do the diff and build the xml | ||
//first try to find the node by id | ||
var nodes = osmSettingsService.getNodes(); | ||
var node = nodes.getElementById(currentNode.properties.id); | ||
var deferred = $q.defer(); //only for errors | ||
if (node === null) { | ||
deferred.reject({ | ||
msg: 'can t find node', | ||
currentNode: currentNode, | ||
updatedNode: updatedNode, | ||
osmNode: node | ||
}); | ||
return deferred.promise; | ||
} | ||
var tag; | ||
node.setAttribute('changeset', osmSettingsService.getChangeset()); | ||
node.setAttribute('user', osmSettingsService.getUserName()); | ||
while (node.getElementsByTagName('tag')[0]){ | ||
node.removeChild(node.getElementsByTagName('tag')[0]); | ||
} | ||
var osm = document.createElement('osm'); | ||
var value; | ||
osm.appendChild(node); | ||
for (var property in updatedNode.properties.tags) { | ||
if (updatedNode.properties.tags.hasOwnProperty(property)) { | ||
value = updatedNode.properties.tags[property]; | ||
if (value === undefined){ | ||
continue; | ||
} | ||
tag = document.createElement('tag'); | ||
tag.setAttribute('k', property); | ||
tag.setAttribute('v', value); | ||
node.appendChild(tag); | ||
} | ||
} | ||
var nodeType; | ||
if (updatedNode.geometry.type === 'Polygon') { | ||
nodeType = 'way'; | ||
} else if (updatedNode.geometry.type === 'Point') { | ||
nodeType = 'node'; | ||
} else if (updatedNode.geometry.type === 'LineString') { | ||
nodeType = 'way'; | ||
} else { | ||
deferred.reject({ | ||
msg: 'geojson type not supported', | ||
currentNode: currentNode, | ||
updatedNode: updatedNode, | ||
osmNode: node | ||
}); | ||
return deferred.promise; | ||
} | ||
//put request !! | ||
var url = '/0.6/' + nodeType + '/' + currentNode.properties.id; | ||
return this.put(url, osm.outerHTML); | ||
this.getNode = function (id) { | ||
return this.get('/0.6/node/' + id); | ||
}; | ||
/** | ||
* @ngdoc method | ||
* @name createNode | ||
* @name deleteNode | ||
* @methodOf osm.api.osmAPI | ||
* @param {Object/string} node as xml or geojson | ||
* @param {string} id | ||
* @returns {Promise} $http.delete response | ||
* DELETE /0.6/node/#id | ||
*/ | ||
this.deleteNode = function (id) { | ||
return this.delete('/0.6/node/' + id); | ||
}; | ||
//------------------ ELEMENTS: WAY ---------------- | ||
/** | ||
* @ngdoc method | ||
* @name createWay | ||
* @methodOf osm.api.osmAPI | ||
* @param {Object/string} way | ||
var way = {osm: {way: { | ||
_changeset: '12', _lat: '...', _lon: '...', | ||
tags: [ | ||
{_k: '...', _v: '...'} | ||
], | ||
nd: [ | ||
{_ref: '123'}, | ||
{_ref: '456'}, | ||
] | ||
}}}; | ||
* @returns {Promise} $http.put response | ||
* /0.6/node/create | ||
* PUT /0.6/way/create | ||
*/ | ||
this.createNode = function (node) { | ||
var xmlnode = node; | ||
if (typeof node === 'object') { | ||
xmlnode = osmUtilsService.createNodeXML(node); | ||
} | ||
return this.put('/0.6/node/create', xmlnode); | ||
this.createWay = function (way) { | ||
return this.put('/0.6/way/create', way); | ||
}; | ||
/** | ||
* @ngdoc method | ||
* @name getMapGeoJSON | ||
* @name getWay | ||
* @methodOf osm.api.osmAPI | ||
* @param {string} bbox the bounding box | ||
* @param {string} id | ||
* @returns {Promise} $http.get response | ||
* GET /0.6/way/#id | ||
*/ | ||
this.getMapGeoJSON = function(bbox){ | ||
var self = this; | ||
var deferred = $q.defer(); | ||
self.getMap(bbox).then(function(strNodes){ | ||
var xmlNodes = osmUtilsService.parseXml(strNodes); | ||
var geojsonNodes = osmUtilsService.getNodesInJSON(xmlNodes); | ||
deferred.resolve(geojsonNodes); | ||
}, function(error){ | ||
deferred.reject(error); | ||
}); | ||
return deferred.promise; | ||
this.getWay = function (id) { | ||
return this.get('/0.6/way/' + id); | ||
}; | ||
/** | ||
* @ngdoc method | ||
* @name deleteWay | ||
* @methodOf osm.api.osmAPI | ||
* @param {string} id | ||
* @returns {Promise} $http.delete response | ||
* DELETE /0.6/way/#id | ||
*/ | ||
this.deleteWay = function (id) { | ||
return this.delete('/0.6/way/' + id); | ||
}; | ||
//------------------ ELEMENTS: RELATION ---------------- | ||
/** | ||
* @ngdoc method | ||
* @name createRelation | ||
* @methodOf osm.api.osmAPI | ||
* @param {Object/string} relation | ||
var relation = {osm: {relation: { | ||
_changeset: '12', _lat: '...', _lon: '...', | ||
tags: [ | ||
{_k: '...', _v: '...'} | ||
], | ||
member: [ | ||
{_type: 'node', _role: 'stop', 'ref': '123'}, | ||
{_type: 'way', 'ref': '234'} | ||
] | ||
}}}; | ||
* @returns {Promise} $http.put response | ||
* PUT /0.6/relation/create | ||
*/ | ||
this.createRelation = function (relation) { | ||
return this.put('/0.6/relation/create', relation); | ||
}; | ||
/** | ||
* @ngdoc method | ||
* @name getRelation | ||
* @methodOf osm.api.osmAPI | ||
* @param {string} id | ||
* @returns {Promise} $http.get response | ||
* GET /0.6/relation/#id | ||
*/ | ||
this.getRelation = function (id) { | ||
return this.get('/0.6/relation/' + id); | ||
}; | ||
/** | ||
* @ngdoc method | ||
* @name deleteRelation | ||
* @methodOf osm.api.osmAPI | ||
* @param {string} id | ||
* @returns {Promise} $http.delete response | ||
* DELETE /0.6/relation/#id | ||
*/ | ||
this.deleteRelation = function (id) { | ||
return this.delete('/0.6/relation/' + id); | ||
}; | ||
} | ||
export default osmAPI; |
@@ -15,8 +15,25 @@ import osmAuthLib from 'osm-auth'; | ||
} | ||
/** | ||
* @ngdoc method | ||
* @name logout | ||
* @methodOf osm.auth.osmAuthService | ||
*/ | ||
this.logout = function () { | ||
return this.auth.logout(); | ||
this.auth.logout(); | ||
}; | ||
/** | ||
* @ngdoc method | ||
* @name authenticated | ||
* @methodOf osm.auth.osmAuthService | ||
* @return {boolean} authenticated | ||
*/ | ||
this.authenticated = function () { | ||
return this.auth.authenticated(); | ||
}; | ||
/** | ||
* @ngdoc method | ||
* @name authenticate | ||
* @methodOf osm.auth.osmAuthService | ||
* @return {Promise} true/false | ||
*/ | ||
this.authenticate = function () { | ||
@@ -29,2 +46,8 @@ var deferred = $q.defer(); | ||
}; | ||
/** | ||
* @ngdoc method | ||
* @name xhr | ||
* @methodOf osm.auth.osmAuthService | ||
* @return {Promise} http response | ||
*/ | ||
this.xhr = function (options) { | ||
@@ -41,2 +64,7 @@ var deferred = $q.defer(); | ||
}; | ||
/** | ||
* @ngdoc method | ||
* @name options | ||
* @methodOf osm.auth.osmAuthService | ||
*/ | ||
this.options = function (options) { | ||
@@ -43,0 +71,0 @@ if (this.auth) { |
@@ -8,2 +8,3 @@ import angular from 'angular'; | ||
import settings from './settings/settings'; | ||
import nominatim from './nominatim/nominatim'; | ||
@@ -15,3 +16,4 @@ angular.module('osm', [ | ||
taginfo.name, | ||
oauth.name | ||
oauth.name, | ||
nominatim.name | ||
]); |
@@ -5,4 +5,13 @@ import osmOverpassAPI from './overpass.service'; | ||
var osmOverpassModule = angular.module('osm.overpass', [osmSettingsModule.name]) | ||
.factory('osmOverpassAPI', osmOverpassAPI); | ||
.factory('osmOverpassAPI', osmOverpassAPI) | ||
.provider('osmOverpassAPI', function osmOverpassAPIProvider () { | ||
this.options = { | ||
url: 'http://overpass-api.de/api/interpreter' | ||
}; | ||
this.$get = function osmOverpassAPIFactory($http, $q, osmSettingsService) { | ||
return new osmOverpassAPI($http, $q, osmSettingsService, this.options); | ||
}; | ||
this.$get.$inject = ['$http', '$q', 'osmSettingsService']; | ||
}); | ||
export default osmOverpassModule; |
@@ -10,101 +10,130 @@ | ||
*/ | ||
osmOverpassAPI.$inject = ['$http', '$q', 'osmSettingsService']; | ||
function osmOverpassAPI($http, $q, osmSettingsService) { | ||
var service = { | ||
overpass: function(query){ | ||
var url = osmSettingsService.getOverpassAPI(); | ||
var deferred = $q.defer(); | ||
var self = this; | ||
var headers = {'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'}; | ||
$http.post( | ||
url, | ||
'data='+encodeURIComponent(query), | ||
{headers: headers} | ||
).then(function(data){ | ||
deferred.resolve(data.data); | ||
}, function(data) { | ||
deferred.reject(data); | ||
}); | ||
return deferred.promise; | ||
}, | ||
overpassToGeoJSON: function(query, filter){ | ||
var deferred = $q.defer(); | ||
var features = []; | ||
var relations = []; | ||
var result = { | ||
type: 'FeatureCollection', | ||
features: features, | ||
relations: relations | ||
function osmOverpassAPI($http, $q, osmSettingsService, options) { | ||
this.url = options.url; | ||
/** | ||
* @ngdoc method | ||
* @name overpass | ||
* @param {Object/String} query | ||
* http://wiki.openstreetmap.org/wiki/FR:Overpass_API | ||
* @methodOf osm.overpass.osmOverpassAPI | ||
* @return {Promise} $http.get | ||
*/ | ||
this.overpass = function (query) { | ||
var self = this; | ||
var url = self.url; | ||
var deferred = $q.defer(); | ||
var headers = {'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'}; | ||
$http.post( | ||
url, | ||
'data=' + encodeURIComponent(query), | ||
{headers: headers} | ||
).then(function (data) { | ||
deferred.resolve(data.data); | ||
}, function (data) { | ||
deferred.reject(data); | ||
}); | ||
return deferred.promise; | ||
}; | ||
/** | ||
* @ngdoc method | ||
* @name overpass | ||
* @description | ||
* http://wiki.openstreetmap.org/wiki/FR:Overpass_API/Overpass_QL#By_area_.28area.29 | ||
By convention the area id can be calculated from an existing OSM way by adding 2400000000 to its OSM id, or in case of a relation by adding 3600000000 respectively. Note that area creation is subject to some extraction rules, i.e. not all ways/relations have an area counterpart (notably those that are tagged with area=no, and most multipolygons and that don't have a defined name=* will not be part of areas). | ||
* @param {String} type 'r'/'relation' or 'w'/'way' | ||
* @param {String/Number} osmId the id of the element | ||
* @methodOf osm.overpass.osmOverpassAPI | ||
* @return {Number} the area id | ||
*/ | ||
this.getAreaId = function (type, osmId) { | ||
var id; | ||
if (typeof osmId === 'string') { | ||
id = parseInt(osmId, 10); | ||
} else { | ||
id = osmId; | ||
} | ||
if (type === 'r' || type === 'relation') { | ||
return 3600000000 + id; | ||
} else if (type === 'w' || type === 'way') { | ||
return 2400000000 + id; | ||
} | ||
}; | ||
this.overpassToGeoJSON = function (query, filter) { | ||
var deferred = $q.defer(); | ||
var features = []; | ||
var relations = []; | ||
var result = { | ||
type: 'FeatureCollection', | ||
features: features, | ||
relations: relations | ||
}; | ||
if (filter === undefined) { | ||
filter = function () {}; | ||
} | ||
this.overpass(query).then(function (data) { | ||
//TODO check if data is XML or JSON, here it's JSON | ||
var node, feature, coordinates; | ||
var cache = {loaded:false}; | ||
function getNodeById (id) { | ||
if (!cache.loaded) { | ||
var tmp; | ||
for (var i = 0; i < data.elements.length; i++) { | ||
tmp = data.elements[i]; | ||
cache[tmp.id] = tmp; | ||
} | ||
} | ||
return cache[id]; | ||
}; | ||
if (filter === undefined) { | ||
filter = function () {}; | ||
} | ||
this.overpass(query).then(function(data){ | ||
//TODO check if data is XML or JSON, here it's JSON | ||
var node, feature, coordinates; | ||
var cache = {loaded:false}; | ||
function getNodeById (id){ | ||
if (!cache.loaded){ | ||
var tmp; | ||
for (var i = 0; i < data.elements.length; i++) { | ||
tmp = data.elements[i]; | ||
cache[tmp.id] = tmp; | ||
for (var i = 0; i < data.elements.length; i++) { | ||
node = data.elements[i]; | ||
if (node.type === 'node') { | ||
feature = { | ||
type: 'Feature', | ||
properties:node.tags, | ||
id: node.id, | ||
geometry: { | ||
type:'Point', | ||
coordinates: [node.lon, node.lat] | ||
} | ||
}; | ||
if (!filter(feature)) { | ||
features.push(feature); | ||
} | ||
return cache[id]; | ||
}; | ||
for (var i = 0; i < data.elements.length; i++) { | ||
node = data.elements[i]; | ||
if (node.type === 'node'){ | ||
feature = { | ||
type: 'Feature', | ||
properties:node.tags, | ||
id: node.id, | ||
geometry: { | ||
type:'Point', | ||
coordinates: [node.lon, node.lat] | ||
} | ||
}; | ||
if (!filter(feature)){ | ||
features.push(feature); | ||
} else if (node.type === 'way') { | ||
coordinates = []; | ||
feature = { | ||
type: 'Feature', | ||
properties:node.tags, | ||
id: node.id, | ||
geometry: { | ||
type:'LineString', | ||
coordinates: coordinates | ||
} | ||
} else if (node.type === 'way'){ | ||
coordinates = []; | ||
feature = { | ||
type: 'Feature', | ||
properties:node.tags, | ||
id: node.id, | ||
geometry: { | ||
type:'LineString', | ||
coordinates: coordinates | ||
} | ||
}; | ||
for (var j = 0; j < node.nodes.length; j++) { | ||
coordinates.push([ | ||
getNodeById(node.nodes[j]).lon, | ||
getNodeById(node.nodes[j]).lat | ||
]); | ||
} | ||
if (!filter(feature)){ | ||
features.push(feature); | ||
} | ||
}else if (node.type === 'relation'){ | ||
result.relations.push({ | ||
ref: node.id, | ||
tags: node.tags, | ||
type: 'relation', | ||
members: node.members | ||
}); | ||
}; | ||
for (var j = 0; j < node.nodes.length; j++) { | ||
coordinates.push([ | ||
getNodeById(node.nodes[j]).lon, | ||
getNodeById(node.nodes[j]).lat | ||
]); | ||
} | ||
if (!filter(feature)) { | ||
features.push(feature); | ||
} | ||
} else if (node.type === 'relation') { | ||
result.relations.push({ | ||
ref: node.id, | ||
tags: node.tags, | ||
type: 'relation', | ||
members: node.members | ||
}); | ||
} | ||
deferred.resolve(result); | ||
}, function(error){ | ||
deferred.reject(error); | ||
}); | ||
return deferred.promise; | ||
} | ||
} | ||
deferred.resolve(result); | ||
}, function (error) { | ||
deferred.reject(error); | ||
}); | ||
return deferred.promise; | ||
}; | ||
return service; | ||
} | ||
export default osmOverpassAPI; |
@@ -9,5 +9,5 @@ import osmSettingsService from './settings.service'; | ||
]) | ||
.factory('osmSettingsService', osmSettingsService); | ||
.service('osmSettingsService', osmSettingsService); | ||
export default osmSettingsModule; | ||
/** | ||
@@ -12,72 +10,41 @@ * @ngdoc service | ||
function osmSettingsService ($localStorage) { | ||
return { | ||
localStorage: $localStorage.$default({ | ||
userName: '', | ||
userID: '', | ||
credentials: '', | ||
nodes: [], | ||
changeset: '', | ||
osmAPI: '', | ||
overpassAPI: '' | ||
}), | ||
getUserName: function(){ | ||
return this.localStorage.userName; | ||
}, | ||
setUserName: function(username){ | ||
this.localStorage.userName = username; | ||
}, | ||
getUserID: function(){ | ||
return this.localStorage.userID; | ||
}, | ||
setUserID: function(userid){ | ||
this.localStorage.userID = userid; | ||
}, | ||
getCredentials: function(){ | ||
return this.localStorage.credentials; | ||
}, | ||
setCredentials: function(credentials){ | ||
this.localStorage.credentials = credentials; | ||
}, | ||
getOSMAPI: function(){ | ||
if (this.localStorage.osmAPI){ | ||
return this.localStorage.osmAPI; | ||
}else{ | ||
return 'http://api.openstreetmap.org/api'; | ||
} | ||
}, | ||
setOSMAPI: function(osmAPI){ | ||
this.localStorage.osmAPI = osmAPI; | ||
}, | ||
getOverpassAPI: function(){ | ||
if (this.localStorage.overpassAPI){ | ||
return this.localStorage.overpassAPI; | ||
}else{ | ||
//return 'http://api.openstreetmap.org/api'; | ||
return 'http://overpass-api.de/api/interpreter'; | ||
} | ||
}, | ||
setOverpassAPI: function(overpassAPI){ | ||
this.localStorage.overpassAPI = overpassAPI; | ||
}, | ||
getNodes: function(){ | ||
return this.localStorage.nodes; | ||
}, | ||
setNodes: function(nodes){ | ||
this.localStorage.nodes = nodes; | ||
}, | ||
getChangeset: function(){ | ||
return this.localStorage.changeset; | ||
}, | ||
setChangeset: function(changeset){ | ||
this.localStorage.changeset = changeset; | ||
}, | ||
getOsmAuth: function () { | ||
return this.localStorage.osmAuth; | ||
}, | ||
setOsmAuth: function (options) { | ||
return this.localStorage.osmAuth = options; | ||
} | ||
this.localStorage = $localStorage.$default({ | ||
userName: '', | ||
userID: '', | ||
credentials: '', | ||
changeset: '' | ||
}); | ||
this.getUserName = function () { | ||
return this.localStorage.userName; | ||
}; | ||
this.setUserName = function (username) { | ||
this.localStorage.userName = username; | ||
}; | ||
this.getUserID = function () { | ||
return this.localStorage.userID; | ||
}; | ||
this.setUserID = function (userid) { | ||
this.localStorage.userID = userid; | ||
}; | ||
this.getCredentials = function () { | ||
return this.localStorage.credentials; | ||
}; | ||
this.setCredentials = function (credentials) { | ||
this.localStorage.credentials = credentials; | ||
}; | ||
this.getChangeset = function () { | ||
return this.localStorage.changeset; | ||
}; | ||
this.setChangeset = function (changeset) { | ||
this.localStorage.changeset = changeset; | ||
}; | ||
this.getOsmAuth = function () { | ||
return this.localStorage.osmAuth; | ||
}; | ||
this.setOsmAuth = function (options) { | ||
this.localStorage.osmAuth = options; | ||
}; | ||
} | ||
export default osmSettingsService; |
@@ -9,17 +9,4 @@ 'use strict'; | ||
modules: 'osm.taginfo', | ||
inject: ['osmTagInfoAPI'], | ||
inject: ['osmTagInfoAPI', '$httpBackend', '$rootScope'], | ||
mocks: { | ||
ng: { | ||
$http: { | ||
get: function ($q, url, config) { | ||
if (url === 'https://taginfo.openstreetmap.org/api/4/key/combinations') { | ||
return $q.when({ | ||
data: { | ||
life: 42 | ||
} | ||
}); | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
@@ -61,2 +48,218 @@ tests: function (deps) { | ||
}); | ||
it('should answer to getKeyCombinations', function() { | ||
var url = 'https://taginfo.openstreetmap.org/api/4/key/combinations'; | ||
deps.$httpBackend.expectGET(url).respond(200, {data: {key: 'combination'}}); | ||
deps.osmTagInfoAPI.getKeyCombinations().then(function (data) { | ||
expect(data.data.key).toBe('combination'); | ||
}); | ||
deps.$rootScope.$digest(); | ||
deps.$httpBackend.flush(); | ||
}); | ||
it('should answer to getKeyDistributionNodes', function() { | ||
var url = 'https://taginfo.openstreetmap.org/api/4/key/distribution/nodes'; | ||
deps.$httpBackend.expectGET(url).respond(200, {data: {key: 'distribution'}}); | ||
deps.osmTagInfoAPI.getKeyDistributionNodes().then(function (data) { | ||
expect(data.data.key).toBe('distribution'); | ||
}); | ||
deps.$rootScope.$digest(); | ||
deps.$httpBackend.flush(); | ||
}); | ||
it('should answer to getKeyDistributionWays', function() { | ||
var url = 'https://taginfo.openstreetmap.org/api/4/key/distribution/ways'; | ||
deps.$httpBackend.expectGET(url).respond(200, {data: {key: 'distribution'}}); | ||
deps.osmTagInfoAPI.getKeyDistributionWays().then(function (data) { | ||
expect(data.data.key).toBe('distribution'); | ||
}); | ||
deps.$rootScope.$digest(); | ||
deps.$httpBackend.flush(); | ||
}); | ||
it('should answer to getKeyStats', function() { | ||
var url = 'https://taginfo.openstreetmap.org/api/4/key/stats'; | ||
deps.$httpBackend.expectGET(url).respond(200, {data: {key: 'stats'}}); | ||
deps.osmTagInfoAPI.getKeyStats().then(function (data) { | ||
expect(data.data.key).toBe('stats'); | ||
}); | ||
deps.$rootScope.$digest(); | ||
deps.$httpBackend.flush(); | ||
}); | ||
it('should answer to getKeyValues', function() { | ||
var url = 'https://taginfo.openstreetmap.org/api/4/key/values'; | ||
deps.$httpBackend.expectGET(url).respond(200, {data: {key: 'values'}}); | ||
deps.osmTagInfoAPI.getKeyValues().then(function (data) { | ||
expect(data.data.key).toBe('values'); | ||
}); | ||
deps.$rootScope.$digest(); | ||
deps.$httpBackend.flush(); | ||
}); | ||
it('should answer to getKeyWikiPages', function() { | ||
var url = 'https://taginfo.openstreetmap.org/api/4/key/wiki_pages'; | ||
deps.$httpBackend.expectGET(url).respond(200, {data: {key: 'wiki_pages'}}); | ||
deps.osmTagInfoAPI.getKeyWikiPages().then(function (data) { | ||
expect(data.data.key).toBe('wiki_pages'); | ||
}); | ||
deps.$rootScope.$digest(); | ||
deps.$httpBackend.flush(); | ||
}); | ||
it('should answer to getKeysAll', function() { | ||
var url = 'https://taginfo.openstreetmap.org/api/4/keys/all'; | ||
deps.$httpBackend.expectGET(url).respond(200, {data: {key: 'all'}}); | ||
deps.osmTagInfoAPI.getKeysAll().then(function (data) { | ||
expect(data.data.key).toBe('all'); | ||
}); | ||
deps.$rootScope.$digest(); | ||
deps.$httpBackend.flush(); | ||
}); | ||
it('should answer to getKeysWikiPages', function() { | ||
var url = 'https://taginfo.openstreetmap.org/api/4/keys/wiki_pages'; | ||
deps.$httpBackend.expectGET(url).respond(200, {data: {key: 'wiki_pages'}}); | ||
deps.osmTagInfoAPI.getKeysWikiPages().then(function (data) { | ||
expect(data.data.key).toBe('wiki_pages'); | ||
}); | ||
deps.$rootScope.$digest(); | ||
deps.$httpBackend.flush(); | ||
}); | ||
it('should answer to getRelationRoles', function() { | ||
var url = 'https://taginfo.openstreetmap.org/api/4/relation/roles'; | ||
deps.$httpBackend.expectGET(url).respond(200, {data: {key: 'roles'}}); | ||
deps.osmTagInfoAPI.getRelationRoles().then(function (data) { | ||
expect(data.data.key).toBe('roles'); | ||
}); | ||
deps.$rootScope.$digest(); | ||
deps.$httpBackend.flush(); | ||
}); | ||
it('should answer to getRelationWikiPages', function() { | ||
var url = 'https://taginfo.openstreetmap.org/api/4/relation/wiki_pages'; | ||
deps.$httpBackend.expectGET(url).respond(200, {data: {key: 'wiki_pages'}}); | ||
deps.osmTagInfoAPI.getRelationWikiPages().then(function (data) { | ||
expect(data.data.key).toBe('wiki_pages'); | ||
}); | ||
deps.$rootScope.$digest(); | ||
deps.$httpBackend.flush(); | ||
}); | ||
it('should answer to getRelationsAll', function() { | ||
var url = 'https://taginfo.openstreetmap.org/api/4/relations/all'; | ||
deps.$httpBackend.expectGET(url).respond(200, {data: {key: 'all'}}); | ||
deps.osmTagInfoAPI.getRelationsAll().then(function (data) { | ||
expect(data.data.key).toBe('all'); | ||
}); | ||
deps.$rootScope.$digest(); | ||
deps.$httpBackend.flush(); | ||
}); | ||
it('should answer to getSearchByKeyAndValue', function() { | ||
var url = 'https://taginfo.openstreetmap.org/api/4/search/by_key_and_value'; | ||
deps.$httpBackend.expectGET(url).respond(200, {data: {key: 'by_key_and_value'}}); | ||
deps.osmTagInfoAPI.getSearchByKeyAndValue().then(function (data) { | ||
expect(data.data.key).toBe('by_key_and_value'); | ||
}); | ||
deps.$rootScope.$digest(); | ||
deps.$httpBackend.flush(); | ||
}); | ||
it('should answer to getSearchByKeyword', function() { | ||
var url = 'https://taginfo.openstreetmap.org/api/4/search/by_keyword'; | ||
deps.$httpBackend.expectGET(url).respond(200, {data: {key: 'by_keyword'}}); | ||
deps.osmTagInfoAPI.getSearchByKeyword().then(function (data) { | ||
expect(data.data.key).toBe('by_keyword'); | ||
}); | ||
deps.$rootScope.$digest(); | ||
deps.$httpBackend.flush(); | ||
}); | ||
it('should answer to getSearchByRole', function() { | ||
var url = 'https://taginfo.openstreetmap.org/api/4/search/by_role'; | ||
deps.$httpBackend.expectGET(url).respond(200, {data: {key: 'by_role'}}); | ||
deps.osmTagInfoAPI.getSearchByRole().then(function (data) { | ||
expect(data.data.key).toBe('by_role'); | ||
}); | ||
deps.$rootScope.$digest(); | ||
deps.$httpBackend.flush(); | ||
}); | ||
it('should answer to getSearchByValue', function() { | ||
var url = 'https://taginfo.openstreetmap.org/api/4/search/by_value'; | ||
deps.$httpBackend.expectGET(url).respond(200, {data: {key: 'by_value'}}); | ||
deps.osmTagInfoAPI.getSearchByValue().then(function (data) { | ||
expect(data.data.key).toBe('by_value'); | ||
}); | ||
deps.$rootScope.$digest(); | ||
deps.$httpBackend.flush(); | ||
}); | ||
it('should answer to getSiteInfo', function() { | ||
var url = 'https://taginfo.openstreetmap.org/api/4/site/info'; | ||
deps.$httpBackend.expectGET(url).respond(200, {data: {key: 'info'}}); | ||
deps.osmTagInfoAPI.getSiteInfo().then(function (data) { | ||
expect(data.data.key).toBe('info'); | ||
}); | ||
deps.$rootScope.$digest(); | ||
deps.$httpBackend.flush(); | ||
}); | ||
it('should answer to getSiteSources', function() { | ||
var url = 'https://taginfo.openstreetmap.org/api/4/site/sources'; | ||
deps.$httpBackend.expectGET(url).respond(200, {data: {key: 'sources'}}); | ||
deps.osmTagInfoAPI.getSiteSources().then(function (data) { | ||
expect(data.data.key).toBe('sources'); | ||
}); | ||
deps.$rootScope.$digest(); | ||
deps.$httpBackend.flush(); | ||
}); | ||
it('should answer to getTagCombinations', function() { | ||
var url = 'https://taginfo.openstreetmap.org/api/4/tag/combinations'; | ||
deps.$httpBackend.expectGET(url).respond(200, {data: {key: 'combination'}}); | ||
deps.osmTagInfoAPI.getTagCombinations().then(function (data) { | ||
expect(data.data.key).toBe('combination'); | ||
}); | ||
deps.$rootScope.$digest(); | ||
deps.$httpBackend.flush(); | ||
}); | ||
it('should answer to getTagDistributionNodes', function() { | ||
var url = 'https://taginfo.openstreetmap.org/api/4/tag/distribution/nodes'; | ||
deps.$httpBackend.expectGET(url).respond(200, {data: {key: 'nodes'}}); | ||
deps.osmTagInfoAPI.getTagDistributionNodes().then(function (data) { | ||
expect(data.data.key).toBe('nodes'); | ||
}); | ||
deps.$rootScope.$digest(); | ||
deps.$httpBackend.flush(); | ||
}); | ||
it('should answer to getTagDistributionWays', function() { | ||
var url = 'https://taginfo.openstreetmap.org/api/4/tag/distribution/ways'; | ||
deps.$httpBackend.expectGET(url).respond(200, {data: {key: 'ways'}}); | ||
deps.osmTagInfoAPI.getTagDistributionWays().then(function (data) { | ||
expect(data.data.key).toBe('ways'); | ||
}); | ||
deps.$rootScope.$digest(); | ||
deps.$httpBackend.flush(); | ||
}); | ||
it('should answer to getTagStats', function() { | ||
var url = 'https://taginfo.openstreetmap.org/api/4/tag/stats'; | ||
deps.$httpBackend.expectGET(url).respond(200, {data: {key: 'stats'}}); | ||
deps.osmTagInfoAPI.getTagStats().then(function (data) { | ||
expect(data.data.key).toBe('stats'); | ||
}); | ||
deps.$rootScope.$digest(); | ||
deps.$httpBackend.flush(); | ||
}); | ||
it('should answer to getTagWikiPages', function() { | ||
var url = 'https://taginfo.openstreetmap.org/api/4/tag/wiki_pages'; | ||
deps.$httpBackend.expectGET(url).respond(200, {data: {key: 'wiki_pages'}}); | ||
deps.osmTagInfoAPI.getTagWikiPages().then(function (data) { | ||
expect(data.data.key).toBe('wiki_pages'); | ||
}); | ||
deps.$rootScope.$digest(); | ||
deps.$httpBackend.flush(); | ||
}); | ||
it('should answer to getTagsPopular', function() { | ||
var url = 'https://taginfo.openstreetmap.org/api/4/tags/popular'; | ||
deps.$httpBackend.expectGET(url).respond(200, {data: {key: 'popular'}}); | ||
deps.osmTagInfoAPI.getTagsPopular().then(function (data) { | ||
expect(data.data.key).toBe('popular'); | ||
}); | ||
deps.$rootScope.$digest(); | ||
deps.$httpBackend.flush(); | ||
}); | ||
it('should answer to getWikiLanguages', function() { | ||
var url = 'https://taginfo.openstreetmap.org/api/4/wiki/languages'; | ||
deps.$httpBackend.expectGET(url).respond(200, {data: {key: 'languages'}}); | ||
deps.osmTagInfoAPI.getWikiLanguages().then(function (data) { | ||
expect(data.data.key).toBe('languages'); | ||
}); | ||
deps.$rootScope.$digest(); | ||
deps.$httpBackend.flush(); | ||
}); | ||
@@ -63,0 +266,0 @@ } |
import osmUtilsService from './utils.service'; | ||
import osmSettingsModule from '../settings/settings'; | ||
import x2jsModule from '../x2js/x2js'; | ||
var osmUtilsModule = angular.module('osm.utils', [osmSettingsModule.name]) | ||
var osmUtilsModule = angular.module('osm.utils', [osmSettingsModule.name, x2jsModule.name]) | ||
.service('osmUtilsService', osmUtilsService); | ||
export default osmUtilsModule; |
@@ -5,113 +5,13 @@ /** | ||
*/ | ||
function osmUtilsService(osmSettingsService) { | ||
this.serializer = new XMLSerializer(); | ||
function osmUtilsService($http, osmSettingsService, osmx2js) { | ||
if (typeof window.DOMParser !== 'undefined') { | ||
let parser = new window.DOMParser(); | ||
this.parseXml = function parseXml(xmlStr) { | ||
return parser.parseFromString(xmlStr, 'application/xml'); | ||
}; | ||
} else if (typeof window.ActiveXObject !== 'undefined') { | ||
this.parseXml = function parseXml(xmlStr) { | ||
var xmlDoc = new window.ActiveXObject('Microsoft.XMLDOM'); | ||
xmlDoc.async = 'false'; | ||
xmlDoc.loadXML(xmlStr); | ||
return xmlDoc; | ||
}; | ||
} else { | ||
throw new Error('No XML parser found'); | ||
} | ||
/** | ||
* @ngdoc method | ||
* @name createNodeXML | ||
* @name relationToGeoJSON | ||
* @methodOf osm.utils.osmUtilsService | ||
* @param {Object} node geojson | ||
* @return {string} XML | ||
* <osm> | ||
<node changeset="12" lat="..." lon="..."> | ||
<tag k="note" v="Just a node"/> | ||
... | ||
</node> | ||
</osm> | ||
*/ | ||
this.createNodeXML = function (node) { | ||
var newNode = '<osm><node changeset="CHANGESET" lat="LAT" lon="LNG">TAGS</node></osm>'; | ||
var tagTPL = '<tag k="KEY" v="VALUE"/>'; | ||
var tags = ''; | ||
var value; | ||
newNode = newNode.replace('CHANGESET', osmSettingsService.getChangeset()); | ||
for (var property in node.tags) { | ||
if (node.tags.hasOwnProperty(property)) { | ||
value = node.tags[property]; | ||
if (value === undefined || value === null) { | ||
continue; | ||
}else{ | ||
tags += tagTPL.replace('KEY', property) | ||
.replace('VALUE', node.tags[property]); | ||
} | ||
} | ||
} | ||
newNode = newNode.replace('TAGS', tags); | ||
newNode = newNode.replace('LNG', node.lng); | ||
newNode = newNode.replace('LAT', node.lat); | ||
return newNode; | ||
}; | ||
/** | ||
* @ngdoc method | ||
* @name serialiseXmlToString | ||
* @methodOf osm.utils.osmUtilsService | ||
* @param {Object} xml document object | ||
* @return {string} XML | ||
*/ | ||
this.serialiseXmlToString = function(xml) { | ||
return this.serializer.serializeToString(xml); | ||
}; | ||
/** | ||
* @ngdoc method | ||
* @name getTagsFromChildren | ||
* @methodOf osm.utils.osmUtilsService | ||
* @param {Object} element document element object | ||
* @return {Object} tags {k1:v1,k2: v2} | ||
*/ | ||
this.getTagsFromChildren = function(element) { | ||
var children, tags; | ||
tags = {}; | ||
for (var i = 0; i < element.children.length; i++) { | ||
children = element.children[i]; | ||
if (children.tagName !== 'tag') { | ||
continue; | ||
} | ||
tags[children.getAttribute('k')] = children.getAttribute('v'); | ||
} | ||
return tags; | ||
}; | ||
/** | ||
* @ngdoc method | ||
* @name getNameFromTags | ||
* @methodOf osm.utils.osmUtilsService | ||
* @param {Object} element document element object | ||
* @return {string} name value | ||
*/ | ||
this.getNameFromTags = function(element) { | ||
var children; | ||
for (var i = 0; i < element.children.length; i++) { | ||
children = element.children[i]; | ||
if (children.tagName !== 'tag') { | ||
continue; | ||
} | ||
if (children.getAttribute('k') === 'name') { | ||
return children.getAttribute('v'); | ||
} | ||
} | ||
}; | ||
/** | ||
* @ngdoc method | ||
* @name relationXmlToGeoJSON | ||
* @methodOf osm.utils.osmUtilsService | ||
* @param {Number} relationId id of the relation | ||
* @param {Object} relationXML document element object | ||
* @param {Object} relation json object | ||
* @return {Object} geojson | ||
*/ | ||
this.relationXmlToGeoJSON = function(relationID, relationXML) { | ||
this.relationToGeoJSON = function(relationID, relation) { | ||
var self = this; | ||
@@ -384,17 +284,9 @@ var features = []; | ||
}; | ||
/** | ||
* @ngdoc method | ||
* @name getNodesInJSON | ||
* @methodOf osm.utils.osmUtilsService | ||
* @param {Object} relationGeoJSON geojson | ||
* @return {Object} relation as geojson sorted | ||
*/ | ||
this.getNodesInJSON = function(xmlNodes, flatProperties) { | ||
osmSettingsService.setNodes(xmlNodes); | ||
var options = {}; | ||
if (flatProperties !== undefined) { | ||
options.flatProperties = flatProperties; | ||
} | ||
return osmtogeojson(xmlNodes, options); | ||
this.x2js = osmx2js; | ||
this.xml2js = function (xml_str) { | ||
return osmx2js.xml2js(xml_str) | ||
}; | ||
this.js2xml = function (json) { | ||
return osmx2js.js2xml(json); | ||
}; | ||
/** | ||
@@ -401,0 +293,0 @@ * @ngdoc method |
HTTP dependency
Supply chain riskContains a dependency which resolves to a remote HTTP URL which could be used to inject untrusted code and reduce overall package reliability.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
533471
45
6867
44
0
0
17
+ Addedx2js@^2.0.1
+ Addedx2js@2.0.1(transitive)
+ Addedxmldom@0.1.31(transitive)
- Removedosmtogeojson@https://github.com/tyrasd/osmtogeojson.git#2.2.11