nakarte

Source code of https://map.sikmir.ru (fork)
git clone git://git.sikmir.ru/nakarte
Log | Files | Refs | LICENSE

commit 039f1b0bce87ca73e6b0ae85d1bba9b9b48ef220
parent 2619d6e7ec19a48b10c70ce8c2b8ef913edf43eb
Author: Sergej Orlov <wladimirych@gmail.com>
Date:   Sun, 12 Nov 2017 23:46:44 +0300

new layer GeocachingSu

Diffstat:
Asrc/lib/leaflet.layer.geocaching-su/index.js | 89+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/lib/leaflet.layer.geocaching-su/style.css | 4++++
Asrc/lib/leaflet.layer.geocaching-su/tr.png | 0
3 files changed, 93 insertions(+), 0 deletions(-)

diff --git a/src/lib/leaflet.layer.geocaching-su/index.js b/src/lib/leaflet.layer.geocaching-su/index.js @@ -0,0 +1,88 @@ +import L from 'leaflet'; +import {fetch} from 'lib/xhr-promise'; +import 'lib/leaflet.layer.canvasMarkers'; +import logging from 'lib/logging'; +import urlViaCorsProxy from 'lib/CORSProxy'; +import {notify} from 'lib/notifications'; +import {decode as utf8_decode} from 'utf8'; +import './style.css'; +import iconFromBackgroundImage from 'lib/iconFromBackgroundImage'; +import {openPopupWindow} from 'lib/popup-window'; + + +const GeocachingSu = L.Layer.CanvasMarkers.extend({ + options: { + scaleDependent: true + }, + + dataUrl: 'http://nakarte.tk/geocachingSu/geocaching_su.json', + + initialize: function(options) { + L.Layer.CanvasMarkers.prototype.initialize.call(this, null, options); + this.on('markerclick', this.openCachePage, this); + }, + + onAdd: function(map) { + L.Layer.CanvasMarkers.prototype.onAdd.call(this, map); + this._loadData(); + }, + + _loadData: function() { + if (this._downloadStarted) { + return; + } + this._downloadStarted = true; + fetch(this.dataUrl, {responseType: 'json'}) + .then( + (xhr) => this._loadMarkers(xhr.response), + (e) => { + this._downloadStarted = false; + logging.captureException(e, { + extra: { + description: 'failed to get geocaching kml', + url: this.url, + status: e.xhr.status + } + } + ); + notify('Failed to get Westra passes data'); + } + ); + }, + + cloneMarker: function(marker) { + return { + latlng: {lat: marker.latlng.lat, lng: marker.latlng.lng}, + label: marker.label, + icon: marker.icon, + _label: marker._label + } + }, + + _loadMarkers: function(data) { + const icon = iconFromBackgroundImage('geocaching-icon'); + + const getLabel = function(marker, zoom) { + return zoom >= 10 ? marker._label : null; + }; + + const markers = data.map(([label, url, lat, lng]) => { + return { + latlng: {lat, lng}, + _label: label, + label: getLabel, + icon, url + } + }); + this.addMarkers(markers); + this._dataLoaded = true; + this.fire('data-loaded'); + }, + + openCachePage: function(e) { + openPopupWindow(e.marker.url, 900, 'geocaching_su'); + } +}); + + +export {GeocachingSu} +\ No newline at end of file diff --git a/src/lib/leaflet.layer.geocaching-su/style.css b/src/lib/leaflet.layer.geocaching-su/style.css @@ -0,0 +1,3 @@ +.geocaching-icon { + background-image: url("tr.png"); +} +\ No newline at end of file diff --git a/src/lib/leaflet.layer.geocaching-su/tr.png b/src/lib/leaflet.layer.geocaching-su/tr.png Binary files differ.