Removed code duplication

pull/18/head
Sami Mokaddem 2017-10-23 14:48:59 +02:00
parent 5c5b27fc2d
commit 4d0136bdb8
1 changed files with 7 additions and 16 deletions

View File

@ -7,7 +7,7 @@ const OSMURL='http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png';
const OSMATTRIB='Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors';
var myOpenStreetMap = L.map('feedDivMap1').setView([0, 0], 1);
var osm = new L.TileLayer(OSMURL, {minZoom: 0, maxZoom: 17, attribution: OSMATTRIB}).addTo(myOpenStreetMap);
var osm = new L.TileLayer(OSMURL, {minZoom: 0, maxZoom: 17}).addTo(myOpenStreetMap);
class MapEvent {
constructor(json, marker) {
@ -60,7 +60,7 @@ class MapEventManager {
this.ping();
this._first_map = false;
} else {
this.setMap(mapevent);
this.rotateMap(mapevent);
}
}
@ -75,8 +75,11 @@ class MapEventManager {
}
// Perform the roration of the map in the openStreetMap pannel
rotateMap() {
rotateMap(mapEvent) {
clearTimeout(this._timeoutRotate); //cancel current map rotation
if (mapEvent == undefined) {
var mapEvent = this.getNextEventToShow();
}
this._latToPing = mapEvent.coord.lat;
this._lonToPing = mapEvent.coord.lon;
var marker = mapEvent.marker;
@ -87,18 +90,6 @@ class MapEventManager {
this._timeoutRotate = setTimeout(function(){ mapEventManager.rotateMap(); }, ROTATIONWAITTIME);
}
setMap(mapEvent) {
clearTimeout(this._timeoutRotate); //cancel current map rotation
this._latToPing = mapEvent.coord.lat;
this._lonToPing = mapEvent.coord.lon;
var marker = mapEvent.marker;
myOpenStreetMap.flyTo([mapEvent.coord.lat, mapEvent.coord.lon], 15);
mapEvent.marker.bindPopup(mapEvent.textMarker).openPopup();
$("#textMap1").fadeOut(400, function(){ $(this).text(mapEvent.text); }).fadeIn(400);
setTimeout(function(){ mapEventManager.rotateMap(); }, ROTATIONWAITTIME);
}
ping() {
var pnts = openStreetMapObj.latLngToPoint(this._latToPing, this._lonToPing);
if (pnts != false) { //sometimes latLngToPoint return false