aboutsummaryrefslogtreecommitdiff
path: root/web/app/view/map/BaseMap.js
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2017-03-28 22:27:44 +1300
committerGitHub <noreply@github.com>2017-03-28 22:27:44 +1300
commit94973f80f543f82630351a7e5943dd4c9150a8b0 (patch)
tree1da6153cd3f9d864ac55481fb563371bcfde7945 /web/app/view/map/BaseMap.js
parent9a5d244db1fe558388ecddccd0d60b674dc53d22 (diff)
parent6c0d7e512c585fe159aa30c8bb844b02bb9d99be (diff)
downloadtrackermap-web-94973f80f543f82630351a7e5943dd4c9150a8b0.tar.gz
trackermap-web-94973f80f543f82630351a7e5943dd4c9150a8b0.tar.bz2
trackermap-web-94973f80f543f82630351a7e5943dd4c9150a8b0.zip
Merge pull request #453 from Abyss777/move_map
Move map related classes to subfolder
Diffstat (limited to 'web/app/view/map/BaseMap.js')
-rw-r--r--web/app/view/map/BaseMap.js146
1 files changed, 146 insertions, 0 deletions
diff --git a/web/app/view/map/BaseMap.js b/web/app/view/map/BaseMap.js
new file mode 100644
index 00000000..ac3b2694
--- /dev/null
+++ b/web/app/view/map/BaseMap.js
@@ -0,0 +1,146 @@
+/*
+ * Copyright 2016 - 2017 Anton Tananaev (anton@traccar.org)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+Ext.define('Traccar.view.map.BaseMap', {
+ extend: 'Ext.panel.Panel',
+ xtype: 'baseMapView',
+
+ layout: 'fit',
+
+ getMap: function () {
+ return this.map;
+ },
+
+ getMapView: function () {
+ return this.mapView;
+ },
+
+ initMap: function () {
+ var server, layer, type, bingKey, lat, lon, zoom, target;
+
+ server = Traccar.app.getServer();
+
+ type = Traccar.app.getPreference('map', null);
+ bingKey = server.get('bingKey');
+
+ if (type === 'custom') {
+ layer = new ol.layer.Tile({
+ source: new ol.source.XYZ({
+ url: server.get('mapUrl'),
+ attributions: [
+ new ol.Attribution({
+ html: ''
+ })
+ ]
+ })
+ });
+ } else if (type === 'bingRoad') {
+ layer = new ol.layer.Tile({
+ source: new ol.source.BingMaps({
+ key: bingKey,
+ imagerySet: 'Road'
+ })
+ });
+ } else if (type === 'bingAerial') {
+ layer = new ol.layer.Tile({
+ source: new ol.source.BingMaps({
+ key: bingKey,
+ imagerySet: 'Aerial'
+ })
+ });
+ } else if (type === 'osm') {
+ layer = new ol.layer.Tile({
+ source: new ol.source.OSM({})
+ });
+ } else {
+ layer = new ol.layer.Tile({
+ source: new ol.source.XYZ({
+ urls: [
+ 'https://cartodb-basemaps-a.global.ssl.fastly.net/light_all/{z}/{x}/{y}.png',
+ 'https://cartodb-basemaps-b.global.ssl.fastly.net/light_all/{z}/{x}/{y}.png',
+ 'https://cartodb-basemaps-c.global.ssl.fastly.net/light_all/{z}/{x}/{y}.png',
+ 'https://cartodb-basemaps-d.global.ssl.fastly.net/light_all/{z}/{x}/{y}.png'
+ ],
+ attributions: [
+ new ol.Attribution({
+ html: [
+ '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> ' +
+ 'contributors, &copy; <a href="https://carto.com/attributions">CARTO</a>'
+ ]
+ })
+ ]
+ })
+ });
+ }
+
+ lat = Traccar.app.getPreference('latitude', Traccar.Style.mapDefaultLat);
+ lon = Traccar.app.getPreference('longitude', Traccar.Style.mapDefaultLon);
+ zoom = Traccar.app.getPreference('zoom', Traccar.Style.mapDefaultZoom);
+
+ this.mapView = new ol.View({
+ center: ol.proj.fromLonLat([lon, lat]),
+ zoom: zoom,
+ maxZoom: Traccar.Style.mapMaxZoom
+ });
+
+ this.map = new ol.Map({
+ target: this.body.dom.id,
+ layers: [layer],
+ view: this.mapView
+ });
+
+ target = this.map.getTarget();
+ if (typeof target === 'string') {
+ target = Ext.get(target).dom;
+ }
+
+ this.map.on('pointermove', function (e) {
+ var hit = this.forEachFeatureAtPixel(e.pixel, function (feature, layer) {
+ return true;
+ });
+ if (hit) {
+ target.style.cursor = 'pointer';
+ } else {
+ target.style.cursor = '';
+ }
+ });
+
+ this.map.on('click', function (e) {
+ if (this.map.hasFeatureAtPixel(e.pixel, {
+ layerFilter: function (layer) {
+ return !layer.get('name');
+ }
+ })) {
+ this.map.forEachFeatureAtPixel(e.pixel, function (feature, layer) {
+ this.fireEvent('selectfeature', feature);
+ }.bind(this));
+ } else {
+ this.fireEvent('deselectfeature');
+ }
+ }, this);
+ },
+
+ listeners: {
+ afterrender: function () {
+ this.initMap();
+ },
+
+ resize: function () {
+ this.map.updateSize();
+ }
+ }
+});