-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathneshan.min.js
5 lines (5 loc) · 6.35 KB
/
neshan.min.js
1
2
3
4
5
//Developer: Maher Ashori
//Email: [email protected]
//Github: https://github.com/maherAshori/Neshan-Map
//version: 0.0.2
var app = angular.module("Neshan", []); app.provider("neshan", function () { var a = {}; this.configs = function (b) { a = b }, this.$get = function () { return a } }), app.directive("neshan", ["$timeout", "$http", "neshan", function (a, b, c) { return { template: "<div class=\"map-wrapper\"><form ng-if=\"activeSearchBox\" ng-submit=\"startSearching()\" class=\"input-group map-search\" ng-class='{\"on\": results.length > 0}' dir=\"ltr\"><input type=\"search\" placeholder=\"{{searchPlaceholderText}}\" ng-model=\"output.searchTerm\" class=\"form-control\" ng-focus=\"inputFocus()\" /><div class=\"search-result\"><ul class=\"list-group p-0 m-0\"><li class=\"list-group-item\" ng-repeat=\"item in results\" ng-click=\"setView(item)\"><div class=\"clearfix d-block text-right\"><h6 class=\"float-right m-0 text-primary\">{{item.title}}</h6><h6 class=\"float-left m-0 text-success\">{{item.region}}</h6></div><div class=\"clearfix d-block text-right text-muted\"><small class=\"m-0\">{{item.neighbourhood}}</small></div><div class=\"clearfix d-block text-right text-muted\"><small>{{item.address}}</small></div></li></ul></div></form><div id=\"{{mapId}}\" class=\"neshan-container\"></div><div class=\"actions\"><button class=\"btn btn-danger\" ng-click=\"removeDestination()\" ng-show=\"showDestinationButton\">\u062D\u0630\u0641 \u0645\u0642\u0635\u062F</button><button class=\"btn btn-success\" ng-show=\"showOriginButton\" ng-click=\"removeOrigin()\">\u062D\u0630\u0641 \u0645\u0628\u062F\u0627\u0621</button><button class=\"btn btn-primary ml-3\" ng-show=\"showDestinationButton && showReverseDirection\" ng-click=\"reverseDirection()\">\u062A\u063A\u06CC\u06CC\u0631 \u0627\u0632 \u0645\u0642\u0635\u062F \u0628\u0647 \u0645\u0628\u062F\u0627\u0621</button></div></div>", scope: { output: "=", mapId: "@?", addMarker: "=?", watchMapType: "=?" }, link: function (d) { var e = "blue"; return d.searchPlaceholderText = c.searchPlaceholderText, d.showReverseDirection = c.reverseDirection, d.mapId || (d.mapId = "map"), c.searchPlaceholderText || (d.searchPlaceholderText = "Place"), c.zoom || (c.zoom = 12), angular.isUndefined(c.zoomControl) && (c.zoomControl = !0), c.timeoutReady || (c.timeoutReady = 0), c.search && !c.serviceKey ? (console.error("serviceKey is undefined! search not work ... more information: https://neshan.org"), !1) : void a(function () { var a = new L.Map(d.mapId, { key: c.mapKey, poi: c.poi, traffic: c.traffic, center: c.defaultCenter, zoom: c.zoom, zoomControl: c.zoomControl }), f = L.layerGroup().addTo(a), g = L.layerGroup().addTo(a), h = L.layerGroup().addTo(a); c.mapType ? a.setMapType(c.mapType) : a.setMapType("standard-day"), d.$watch("watchMapType", function (b) { null != b && (a.setMapType(b), "standard-night" === b && (e = "white")) }, !0), d.output = {}; var i, j, k, l = []; if (c.direction) { var m, n, o, p = L.icon({ iconUrl: "https://static.neshan.org/assets/angular-direction/origin.png", iconSize: [60, 60] }), q = L.icon({ iconUrl: "https://static.neshan.org/assets/angular-direction/destination.png", iconSize: [60, 60] }); const i = function (d, f) { var h = { origin: [d._latlng.lat, d._latlng.lng], destination: [f._latlng.lat, f._latlng.lng] }; b({ method: "GET", url: "https://api.neshan.org/v2/direction", params: h, headers: { "Api-Key": c.serviceKey } }).then(function (b) { if (200 === b.status) { const h = b.data.routes[0].legs[0]; var c = [], d = [], f = []; if (angular.forEach(h.steps, function (a) { d.push(a.polyline) }), angular.isDefined(L.Polyline.fromEncoded)) angular.forEach(d, function (a) { var b = L.Polyline.fromEncoded(a); angular.forEach(b._latlngs, function (a) { c.push(a) }) }); else return console.error("please add Polyline.encoded.js file"), !1; angular.forEach(c, function (a) { f.push([a.lat, a.lng]) }), o = L.polyline(f, { color: e }).addTo(g), a.fitBounds(o.getBounds()) } }) }; a.on("click", function (a) { m ? (n && d.removeDestination(), n = L.marker([a.latlng.lat, a.latlng.lng], { icon: q }).addTo(h), d.showDestinationButton = !0, d.showOriginButton = !1, i(m, n)) : (m = L.marker([a.latlng.lat, a.latlng.lng], { icon: p }).addTo(f), d.showOriginButton = !0), d.$apply() }), c.reverseDirection && (d.reverseDirection = function () { a.removeLayer(o); var b = angular.copy(m), c = angular.copy(n); f.clearLayers(), h.clearLayers(), g.clearLayers(), m = L.marker([c._latlng.lat, c._latlng.lng], { icon: p }).addTo(f), n = L.marker([b._latlng.lat, b._latlng.lng], { icon: q }).addTo(h), i(m, n) }), d.removeDestination = function () { d.showDestinationButton = !1, d.showOriginButton = !0, n = void 0, o = void 0, h.clearLayers(), g.clearLayers() }, d.removeOrigin = function () { d.showOriginButton = !1, m = void 0, f.clearLayers() } } else { d.addMarker && (k = new L.Marker([d.addMarker[0], d.addMarker[1]]).addTo(a)); const f = function (a, e) { b({ method: "GET", url: "https://api.neshan.org/v2/reverse", params: { lat: a, lng: e }, headers: { "Api-Key": c.serviceKey } }).then(function (a) { if (200 === a.status) { const b = a.data; c.singleMarker ? (d.output.lat = i, d.output.lng = j, d.output.address = b) : l.push({ lat: i, lng: j, address: b }) } }) }; c.activeMarker && a.on("click", function (b) { d.results = [], c.singleMarker && k && a.removeLayer(k), k = new L.Marker([b.latlng.lat, b.latlng.lng]).addTo(a), i = b.latlng.lat, j = b.latlng.lng, c.singleMarker ? c.reverseGeocoding ? f(i, j) : (d.output.lat = i, d.output.lng = j) : (c.reverseGeocoding ? f(i, j) : l.push({ lat: b.latlng.lat, lng: b.latlng.lng }), d.output.latLag = l), d.$apply() }) } if (c.search && c.serviceKey) { d.activeSearchBox = !0; var r = [], s = []; d.startSearching = function () { var a = { term: d.output.searchTerm, lat: void 0 === i ? c.defaultCenter[0] : i, lng: void 0 === j ? c.defaultCenter[1] : j }; b({ method: "GET", url: "https://api.neshan.org/v1/search", params: a, headers: { "Api-Key": c.serviceKey } }).then(function (a) { if (200 === a.status) { const b = a.data; d.results = b.items, s = angular.copy(b.items), r = angular.copy(d.output.searchTerm) } }) }, d.inputFocus = function () { d.output.searchTerm === r && (d.results = s) }, d.setView = function (b) { a.setView(new L.LatLng(b.location.y, b.location.x), a.getZoom()), k && a.removeLayer(k), k = new L.Marker([b.location.y, b.location.x]).addTo(a), d.results = [] } } }, d.timeoutReady) } } }]);