map-alliance/src/main.ts

69 lines
2.3 KiB
TypeScript
Raw Normal View History

2019-07-02 08:11:23 -04:00
import 'hammerjs';
2019-08-24 11:26:30 -04:00
import {enableProdMode} from '@angular/core';
import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
2019-07-02 08:11:23 -04:00
2019-08-24 11:26:30 -04:00
import {AppModule} from './app/app.module';
import {environment} from './environments/environment';
2019-07-02 08:11:23 -04:00
if (environment.production) {
2019-08-24 11:26:30 -04:00
enableProdMode();
2019-07-02 08:11:23 -04:00
}
platformBrowserDynamic().bootstrapModule(AppModule)
2019-08-24 11:26:30 -04:00
.catch(err => console.error(err));
// Add touch events to leaflet
declare const L;
L.Map.mergeOptions({touchExtend: true});
L.Map.TouchExtend = L.Handler.extend({
initialize: function (map) {
this._map = map;
this._container = map._container;
this._pane = map._panes.overlayPane;
},
addHooks: function () {
L.DomEvent.on(this._container, 'touchstart', this._onTouchStart, this);
L.DomEvent.on(this._container, 'touchend', this._onTouchEnd, this);
L.DomEvent.on(this._container, 'touchmove', this._onTouchMove, this);
},
removeHooks: function () {
L.DomEvent.off(this._container, 'touchstart', this._onTouchStart);
L.DomEvent.off(this._container, 'touchend', this._onTouchEnd);
L.DomEvent.off(this._container, 'touchmove', this._onTouchMove);
},
_onTouchStart: function (e) {
if (!this._map._loaded) return;
var containerPoint = this._map.mouseEventToContainerPoint(e),
layerPoint = this._map.containerPointToLayerPoint(containerPoint),
latlng = this._map.layerPointToLatLng(layerPoint);
this._map.fire('touchstart', {
latlng: latlng,
layerPoint: layerPoint,
containerPoint: containerPoint,
originalEvent: e
});
},
_onTouchEnd: function (e) {
if (!this._map._loaded) return;
this._map.fire('touchend', {originalEvent: e});
},
_onTouchMove: function(e) {
if(!this._map._loaded) return;
console.log('fire');
var containerPoint = this._map.mouseEventToContainerPoint(e),
layerPoint = this._map.containerPointToLayerPoint(containerPoint),
latlng = this._map.layerPointToLatLng(layerPoint);
this._map.fire('touchmove', {
latlng: latlng,
layerPoint: layerPoint,
containerPoint: containerPoint,
originalEvent: e
});
}
});
L.Map.addInitHook('addHandler', 'touchExtend', L.Map.TouchExtend);