2016-04-01 18:31:07 +08:00
<!DOCTYPE HTML>
<!--
2018-06-12 00:08:26 +08:00
Copyright 2015, 2018 IBM Corp.
2016-04-01 18:31:07 +08:00
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
2018-07-01 23:34:23 +08:00
https://www.apache.org/licenses/LICENSE-2.0
2016-04-01 18:31:07 +08:00
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
2016-06-09 05:07:54 +08:00
< html manifest = "worldmap.appcache" >
2016-04-01 18:31:07 +08:00
< head >
< title > Node-RED map all the things< / title >
< meta name = "mobile-web-app-capable" content = "yes" >
< meta name = "viewport" content = "width=device-width, initial-scale=1" >
< link rel = "stylesheet" , type = "text/css" href = "css/map.css" / >
< link rel = "stylesheet" , type = "text/css" href = "leaflet/leaflet.css" / >
< link rel = "stylesheet" , type = "text/css" href = "leaflet/font-awesome/css/font-awesome.min.css" / >
< link rel = "stylesheet" , type = "text/css" href = "leaflet/Leaflet.vector-markers.css" >
< link rel = "stylesheet" , type = "text/css" href = "leaflet/MarkerCluster.css" >
< link rel = "stylesheet" , type = "text/css" href = "leaflet/MarkerCluster.Default.css" >
< link rel = "stylesheet" , type = "text/css" href = "leaflet/leaflet.draw.css" >
< link rel = "stylesheet" , type = "text/css" href = "leaflet/leaflet.measurecontrol.css" >
< link rel = "stylesheet" , type = "text/css" href = "leaflet/easy-button.css" >
2016-05-31 16:21:25 +08:00
< link rel = "stylesheet" , type = "text/css" href = "leaflet/leaflet.fullscreen.css" >
2018-06-03 23:12:13 +08:00
< link rel = "stylesheet" , type = "text/css" href = "leaflet/leaflet-velocity.min.css" >
2016-04-01 18:31:07 +08:00
< link rel = "shortcut icon" type = "image/ico" href = "favicon.ico" / >
2016-05-19 06:26:08 +08:00
2017-09-06 23:00:37 +08:00
< script type = "text/javascript" src = "leaflet/sockjs.min.js" > < / script >
2016-04-01 18:31:07 +08:00
< script type = "text/javascript" src = "leaflet/leaflet.js" > < / script >
< script type = "text/javascript" src = "leaflet/Leaflet.vector-markers.min.js" > < / script >
< script type = "text/javascript" src = "leaflet/leaflet.boatmarker.js" > < / script >
< script type = "text/javascript" src = "leaflet/leaflet.markercluster.js" > < / script >
2016-06-27 18:55:30 +08:00
< script type = "text/javascript" src = "leaflet/leaflet.markercluster.freezable-src.js" > < / script >
2016-04-01 18:31:07 +08:00
< script type = "text/javascript" src = "leaflet/leaflet.active-layers.min.js" > < / script >
< script type = "text/javascript" src = "leaflet/leaflet.select-layers.min.js" > < / script >
< script type = "text/javascript" src = "leaflet/leaflet.draw.js" > < / script >
< script type = "text/javascript" src = "leaflet/leaflet.measurecontrol.js" > < / script >
< script type = "text/javascript" src = "leaflet/easy-button.js" > < / script >
2016-06-02 00:19:04 +08:00
< script type = "text/javascript" src = "leaflet/Leaflet.fullscreen.min.js" > < / script >
2016-04-01 18:31:07 +08:00
< script type = "text/javascript" src = "leaflet/l.ellipse.min.js" > < / script >
2018-06-01 00:32:29 +08:00
< script type = "text/javascript" src = "leaflet/milsymbol.js" > < / script >
2018-09-20 03:50:06 +08:00
< script type = "text/javascript" src = "leaflet/nvg.js" > < / script >
2016-04-01 18:31:07 +08:00
< script type = "text/javascript" src = "leaflet/leaflet-heat.js" > < / script >
< script type = "text/javascript" src = "leaflet/TileLayer.Grayscale.js" > < / script >
< script type = "text/javascript" src = "leaflet/TileLayer.GrayscaleWMS.js" > < / script >
< script type = "text/javascript" src = "leaflet/L.Terminator.js" > < / script >
2018-06-03 23:12:13 +08:00
< script type = "text/javascript" src = "leaflet/leaflet-velocity.min.js" > < / script >
2016-04-01 18:31:07 +08:00
< script type = "text/javascript" src = "leaflet/tile.stamen.js" > < / script >
2016-10-19 05:37:07 +08:00
< script type = "text/javascript" src = "leaflet/OSMBuildings-Leaflet.js" > < / script >
2018-06-27 03:42:24 +08:00
< script type = "text/javascript" src = "leaflet/leaflet-omnivore.min.js" > < / script >
2016-05-16 23:07:23 +08:00
< script type = "text/javascript" src = "leaflet/dialog-polyfill.js" > < / script >
< link rel = "stylesheet" type = "text/css" href = "leaflet/dialog-polyfill.css" / >
2016-04-01 18:31:07 +08:00
< / head >
2017-09-06 23:00:37 +08:00
< body onunload = "ws.send(JSON.stringify({'action':'end'}));" >
2016-04-01 18:31:07 +08:00
< div id = "topbar" >
2018-07-01 23:34:23 +08:00
< a href = "https://nodered.org" > < img src = "images/node-red.png" width = "60px" height = "24px" / > < / a >
2016-06-06 01:37:17 +08:00
< span class = "topbar" > Node-RED - map all the things< / span >
2016-04-01 18:31:07 +08:00
< / div >
< div id = "results" >
< span id = "searchRes" > < / span >
2016-06-02 06:40:38 +08:00
< span id = "bars" onclick = 'toggleMenu()' onmouseover = 'toggleMenu()' > < i class = "fa fa-bars fa-2x fa-inverse" > < / i > < / span >
2016-04-01 18:31:07 +08:00
< / div >
< div id = "menu" > < table >
< tr > < td > < input type = 'text' name = 'search' id = 'search' size = '20' style = "width:150px;" / > < span onclick = 'doSearch();' > < i class = "fa fa-search fa-lg" > < / i > < / span > < / td > < / tr >
2016-06-06 01:37:17 +08:00
< tr > < td style = "cursor:default" > < i class = "fa fa-spinner fa-lg fa-fw" > < / i > Set Max Age < input type = 'text' name = 'maxage' id = 'maxage' value = "600" size = "5" onchange = 'setMaxAge();' / > s< / td > < / tr >
2018-06-07 06:45:06 +08:00
< tr > < td style = "cursor:default" > < i class = "fa fa-search-plus fa-lg fa-fw" > < / i > Cluster at zoom < < input type = 'text' name = 'setclus' id = 'setclus' size = "2" onchange = 'setCluster();' / > < / td > < / tr >
2016-06-06 01:37:17 +08:00
< tr > < td style = "cursor:default" > < input type = 'checkbox' name = 'panit' onclick = 'doPanit();' / > Auto Pan Map< / td > < / tr >
< tr > < td style = "cursor:default" > < input type = 'checkbox' name = 'lockit' onclick = 'doLock();' / > Lock Map< / td > < / tr >
< tr > < td style = "cursor:default" > < input type = 'checkbox' name = 'heatall' onclick = 'doHeatAll();' / > Heatmap all layers< / td > < / tr >
< tr > < td style = "cursor:default" > < span id = "showHelp" > < i class = "fa fa-info fa-lg fa-fw" > < / i > Help< / span > < / td > < / tr >
2016-04-01 18:31:07 +08:00
< / table > < / div >
< div id = "map" > < / div >
2016-11-22 16:21:56 +08:00
< div id = "foot" > < / div >
2016-04-01 18:31:07 +08:00
<!-- <div id="heat"><button type="button" onclick="clearHeat();">Clear Heatmap</button></div> -->
< dialog id = "helpWindow" >
< h3 > Node-RED - Map all the things< / h3 >
< p > < i class = "fa fa-search fa-lg fa-fw" > < / i > Search - You may enter a name or partial name of an object to search for.< br / >
The map will then jump to centre on each of the results.< / p >
2016-05-17 15:47:45 +08:00
< p > < i class = "fa fa-spinner fa-lg fa-fw" > < / i > Set Max Age - You can set the time after which points
2016-04-01 18:31:07 +08:00
that haven't been updated get removed.< / p >
2016-05-17 19:22:04 +08:00
< p > < i class = "fa fa-search-plus fa-lg fa-fw" > < / i > Cluster at zoom - by default multiple objects will be clustered at zoom levels less than 12.< / p >
2016-04-01 18:31:07 +08:00
< p > < i class = "fa fa-arrows fa-lg fa-fw" > < / i > Auto Pan - When selected, the map will
automatically move to centre on each data point as they arrive.< / p >
< p > < i class = "fa fa-lock fa-lg fa-fw" > < / i > Lock Map - When selected will save the
currently displayed area and basemap.< br / >
Reloading the map in the current browser will return to the same view.< br / >
This can be used to set your initial start position.< br / >
While active it also restricts the "auto pan" to within that area.< / p >
< p > < i class = "fa fa-globe fa-lg fa-fw" > < / i > Heatmap all layers - When selected
all layers whether hidden or not will contribute to the heatmap.< br / >
The default is that only visible layers add to the heatmap.< / p >
< button id = "exitHelp" > Close< / button >
< / dialog >
< script language = "javascript" type = "text/javascript" >
2016-05-08 18:07:09 +08:00
var startpos = [51.03, -1.379]; // Start location - somewhere in UK :-)
2016-04-01 18:31:07 +08:00
var startzoom = 10;
var map;
var markers = {};
var polygons = {};
var layers = {};
var overlays = {};
var basemaps = {};
var marks = [];
var marksIndex = 0;
var popid = "";
var menuOpen = false;
2018-06-07 06:45:06 +08:00
var clusterAt = 13;
2016-05-08 18:07:09 +08:00
var maxage = 600; // default max age of icons on map in seconds - cleared after 10 mins
var baselayername = "OSM grey"; // Default base layer OSM but uniform grey
2018-06-12 00:08:26 +08:00
var ibmfoot = " © IBM 2015,2018"
2016-06-12 19:40:29 +08:00
var initialposition = false;
2016-11-22 16:21:56 +08:00
var inIframe = false;
var showUserMenu = true;
2017-10-11 06:51:18 +08:00
var showLayerMenu = true;
var layercontrol;
2017-09-06 23:00:37 +08:00
var ws;
2016-04-01 18:31:07 +08:00
2018-06-01 00:32:29 +08:00
var iconSz = {
2018-09-20 03:50:06 +08:00
"Team/Crew": 17.5,
"Squad": 20,
"Section": 22.5,
"Platoon/detachment": 25,
"Company/battery/troop": 27.5,
2018-06-01 00:32:29 +08:00
"Battalion/squadron": 30,
2018-09-20 03:50:06 +08:00
"Regiment/group": 32.5,
"Brigade": 35,
"Division": 37.5,
"Corps/MEF": 40,
"Army": 45,
"Army Group/front": 50,
"Region/Theater": 50,
"Command": 50
2018-06-01 00:32:29 +08:00
};
2016-05-25 04:34:18 +08:00
// Create the socket
2017-09-06 23:00:37 +08:00
var connect = function() {
2018-07-01 23:34:23 +08:00
ws = new SockJS(location.pathname.split("index")[0] + 'socket');
2017-09-06 23:00:37 +08:00
ws.onopen = function() {
console.log("CONNECTED");
if (!inIframe) {
document.getElementById("foot").innerHTML = "< font color = '#494' > "+ibmfoot+"< / font > ";
2017-08-14 01:31:53 +08:00
}
2017-09-06 23:00:37 +08:00
ws.send(JSON.stringify({action:"connected"}));
};
ws.onclose = function() {
console.log("DISCONNECTED");
if (!inIframe) {
document.getElementById("foot").innerHTML = "< font color = '#900' > "+ibmfoot+"< / font > ";
}
setTimeout(function() { connect(); }, 2500);
};
ws.onmessage = function(e) {
var data = JSON.parse(e.data);
//console.log("DATA",data);
if (Array.isArray(data)) {
//console.log("ARRAY");
for (var prop in data) {
if (data[prop].command) { doCommand(data[prop].command); delete data[prop].command; }
if (data[prop].hasOwnProperty("name")) { setMarker(data[prop]); }
2018-06-07 06:45:06 +08:00
else { console.log("SKIP A",data[prop]); }
2017-09-06 23:00:37 +08:00
}
}
else {
if (data.command) { doCommand(data.command); delete data.command; }
2018-06-12 00:08:26 +08:00
if (data.hasOwnProperty("name")) { setMarker(data); }
2017-09-06 23:00:37 +08:00
else { console.log("SKIP",data); }
}
};
}
console.log("CONNECT TO",location.pathname + 'socket');
connect();
2016-05-25 04:34:18 +08:00
2018-07-01 23:34:23 +08:00
document.addEventListener ("keydown", function (ev) {
if (ev.ctrlKey & & ev.altKey & & ev.code === "Digit3") {
ws.close();
2018-08-21 21:45:43 +08:00
//window.onbeforeunload = null;
2018-07-01 23:34:23 +08:00
window.location.href = "index3d.html";
}
});
2016-04-01 18:31:07 +08:00
if ( window.localStorage.hasOwnProperty("lastpos") ) {
2016-06-12 19:40:29 +08:00
initialposition = true;
2016-05-20 23:41:13 +08:00
var sp = JSON.parse(window.localStorage.getItem("lastpos"));
2016-04-01 18:31:07 +08:00
startpos = [ sp.lat, sp.lng ];
}
if ( window.localStorage.hasOwnProperty("lastzoom") ) {
2016-05-20 23:41:13 +08:00
startzoom = window.localStorage.getItem("lastzoom");
}
2016-06-27 18:55:30 +08:00
// if ( window.localStorage.hasOwnProperty("clusterat") ) {
// clusterAt = window.localStorage.getItem("clusterat");
// document.getElementById("setclus").value = clusterAt;
// }
2016-05-20 23:41:13 +08:00
if ( window.localStorage.hasOwnProperty("maxage") ) {
maxage = window.localStorage.getItem("maxage");
2016-05-27 05:12:56 +08:00
document.getElementById("maxage").value = maxage;
2016-04-01 18:31:07 +08:00
}
2016-05-27 05:12:56 +08:00
2016-04-01 18:31:07 +08:00
// Create the Initial Map object.
map = new L.map('map').setView(startpos, startzoom);
2018-10-13 06:58:20 +08:00
var menuButton = L.easyButton({states:[{icon:'fa-bars fa-lg', onClick:function() { toggleMenu(); }, title:'Toggle menu'}], position:"topright"});
//var colorPickButton = L.easyButton({states:[{icon:'fa-tint fa-lg', onClick:function() { console.log("PICK"); }, title:'Pick Colour'}]});
var redButton = L.easyButton('fa-square wm-red', function(btn) { console.log("RED",btn); })
var blueButton = L.easyButton('fa-square wm-blue', function(btn) { console.log("BLUE",btn); })
var greenButton = L.easyButton('fa-square wm-green', function(btn) { console.log("GREEN",btn); })
var yellowButton = L.easyButton('fa-square wm-yellow', function(btn) { console.log("YELLOW",btn); })
var blackButton = L.easyButton('fa-square wm-black', function(btn) { console.log("BLACK",btn); })
var colorControl = L.easyBar([redButton,blueButton,greenButton,yellowButton,blackButton]);
2017-09-06 23:00:37 +08:00
2016-05-31 16:21:25 +08:00
// Move some bits around if in an iframe
2016-05-27 05:12:56 +08:00
if (window.self !== window.top) {
2016-06-02 06:40:38 +08:00
console.log("IN an iframe");
2016-11-22 16:21:56 +08:00
inIframe = true;
2016-05-27 05:12:56 +08:00
(document.getElementById("topbar").style.display="none");
(document.getElementById("map").style.top="0px");
(document.getElementById("results").style.right="50px");
(document.getElementById("results").style.top="10px");
(document.getElementById("results").style.zIndex="1");
(document.getElementById("results").style.height="31px");
(document.getElementById("results").style.paddingTop="6px");
(document.getElementById("bars").style.display="none");
(document.getElementById("menu").style.right="8px");
(document.getElementById("menu").style.borderRadius="6px");
}
else {
2016-05-31 16:21:25 +08:00
console.log("NOT in an iframe")
2018-08-21 21:45:43 +08:00
// window.onbeforeunload = function(e) {
// return 'Reloading will delete all the local markers, including any drawing on the "drawing" layer';
// };
2016-11-22 16:21:56 +08:00
if (!showUserMenu) {
document.getElementById("bars").style.display="none";
}
2016-05-27 05:12:56 +08:00
}
2016-11-22 16:21:56 +08:00
if (!inIframe) {
// Add the fullscreen button
L.control.fullscreen().addTo(map);
2016-05-31 16:21:25 +08:00
2016-11-22 16:21:56 +08:00
// map.on('fullscreenchange', function () {
// if (map.isFullscreen()) { console.log('entered fullscreen') }
// else { console.log('exited fullscreen'); }
// });
2016-05-31 16:21:25 +08:00
2016-11-22 16:21:56 +08:00
// Add the locate my position button
L.easyButton( 'fa-crosshairs fa-lg', function() {
map.locate({setView:true, maxZoom:16});
}, "Locate me").addTo(map);
2016-05-31 16:21:25 +08:00
2016-11-22 16:21:56 +08:00
// Add the measure/ruler button
L.Control.measureControl().addTo(map);
2016-05-31 16:21:25 +08:00
2016-11-22 16:21:56 +08:00
// Create the clear heatmap button
var clrHeat = L.easyButton( '< b > Reset Heatmap< / b > ', function() {
2017-05-15 20:55:22 +08:00
console.log("Reset heatmap");
2016-11-22 16:21:56 +08:00
heat.setLatLngs([]);
}, "Clears the current heatmap", "bottomright");
}
2018-06-07 01:13:50 +08:00
else { if (showUserMenu) { menuButton.addTo(map); } }
2016-04-01 18:31:07 +08:00
2018-10-13 06:58:20 +08:00
2016-05-17 15:47:45 +08:00
// Handle the dialog for popup help
2016-05-16 23:07:23 +08:00
var dialog = document.querySelector('dialog');
dialogPolyfill.registerDialog(dialog);
2016-04-01 18:31:07 +08:00
document.getElementById('showHelp').onclick = function() {
dialog.show();
};
document.getElementById('exitHelp').onclick = function() {
dialog.close();
};
var panit = false;
function doPanit() {
panit = !panit;
console.log("Panit set :",panit);
}
var heatAll = false;
function doHeatAll() {
heatAll = !heatAll;
console.log("Heatall set :",heatAll);
}
var lockit = false;
var mb = new L.LatLngBounds([[-120,-360],[120,360]]);
function doLock() {
if (lockit) {
lockit = false;
mb = new L.LatLngBounds([[-120,-360],[120,360]]);
}
else {
lockit = true;
mb = map.getBounds();
window.localStorage.setItem("lastpos",JSON.stringify(map.getCenter()));
window.localStorage.setItem("lastzoom", map.getZoom());
window.localStorage.setItem("lastlayer", baselayername);
2016-06-15 19:57:31 +08:00
//window.localStorage.setItem("clusterat", clusterAt);
2016-05-20 23:41:13 +08:00
window.localStorage.setItem("maxage", maxage);
2016-04-01 18:31:07 +08:00
console.log("Saved :",JSON.stringify(map.getCenter()),map.getZoom(),baselayername);
}
map.setMaxBounds(mb);
console.log("Map bounds lock :",lockit);
}
// Remove old markers
2017-11-02 01:16:58 +08:00
function doTidyUp(l) {
2016-04-01 18:31:07 +08:00
var d = parseInt(Date.now()/1000);
for (var m in markers) {
2017-11-02 01:16:58 +08:00
if ((l & & (l == markers[m].lay)) || typeof markers[m].ts != "undefined") {
2016-04-01 18:31:07 +08:00
//console.log(m,markers[m].ts,markers[m]);
2017-11-02 01:16:58 +08:00
if ((l & & (l == markers[m].lay)) || (markers[m].hasOwnProperty("ts") & & (Number(markers[m].ts) < d ) & & ( markers [ m ] . lay ! = = " _drawing " ) ) ) {
2016-04-01 18:31:07 +08:00
//console.log("STALE :",m);
layers[markers[m].lay].removeLayer(markers[m]);
if (typeof polygons[m] != "undefined") {
layers[markers[m].lay].removeLayer(polygons[m]);
delete polygons[m];
}
2017-05-15 20:55:22 +08:00
if (typeof polygons[m+"_"] != "undefined") {
2017-09-06 23:00:37 +08:00
layers[polygons[m+"_"].lay].removeLayer(polygons[m+"_"]);
2017-05-15 20:55:22 +08:00
delete polygons[m+"_"];
}
2016-04-01 18:31:07 +08:00
delete markers[m];
}
}
}
2018-10-03 21:57:14 +08:00
if (l) {
if (layers[l]) { map.removeLayer(layers[l]); layercontrol.removeLayer(layers[l]); delete layers[l]; }
if (overlays[l]) { map.removeLayer(overlays[l]); layercontrol.removeLayer(overlays[l]); delete overlays[l]; }
}
2016-04-01 18:31:07 +08:00
}
2016-05-08 18:07:09 +08:00
// move the daylight / nighttime boundary (if enabled) every minute
2016-04-01 18:31:07 +08:00
function moveTerminator() { // if terminator line plotted move it every minute
if (layers["_daynight"].getLayers().length > 0) {
layers["_daynight"].clearLayers();
layers["_daynight"].addLayer(L.terminator());
}
}
setInterval( function() {moveTerminator()}, 60000 );
2016-05-08 18:07:09 +08:00
// Call tidyup every {maxage} seconds - default 10 mins
2016-04-01 18:31:07 +08:00
var stale = null;
function setMaxAge() {
maxage = document.getElementById('maxage').value;
if (stale) { clearInterval(stale); }
2017-11-02 01:16:58 +08:00
//if (maxage > 0) {
stale = setInterval( function() {doTidyUp()}, 20000); // every 20 secs
//} //every minute
2016-04-01 18:31:07 +08:00
//console.log("Stale time set :",maxage+"s");
}
setMaxAge();
2018-06-07 06:45:06 +08:00
function setCluster(v) {
clusterAt = v || 0;
2018-06-12 00:08:26 +08:00
console.log("clusterAt set:",clusterAt);
2016-06-27 18:55:30 +08:00
showMapCurrentZoom();
2016-05-17 19:22:04 +08:00
}
2018-06-07 06:45:06 +08:00
//setCluster();
2016-05-17 19:22:04 +08:00
2016-04-01 18:31:07 +08:00
// Search for markers with names of ....
function doSearch() {
var value = document.getElementById('search').value;
console.log("Search for :",value);
marks = [];
marksIndex = 0;
for (var key in markers) {
if ( (~(key.toLowerCase()).indexOf(value.toLowerCase())) & & (mb.contains(markers[key].getLatLng()))) {
marks.push(markers[key]);
}
}
moveToMarks();
if (lockit) {
document.getElementById('searchRes').innerHTML = " < font color = '#ff0' > Found "+marks.length+" results within bounds.< / font > ";
} else {
document.getElementById('searchRes').innerHTML = " < font color = '#ff0' > Found "+marks.length+" results.< / font > ";
}
}
// Jump to a markers position - centralise it on map
function moveToMarks() {
if (marks.length > marksIndex) {
var m = marks[marksIndex];
map.setView(m.getLatLng(), map.getZoom());
m.openPopup();
marksIndex++;
2016-05-08 18:07:09 +08:00
setTimeout(moveToMarks, 2500);
2016-04-01 18:31:07 +08:00
}
}
function toggleMenu() {
menuOpen = !menuOpen;
if (menuOpen) {
document.getElementById("menu").style.display = 'block';
} else {
document.getElementById("menu").style.display = 'none';
}
}
document.getElementById("menu").style.display = 'none';
//function clearHeat() {
2016-05-19 06:26:08 +08:00
//console.log("reset heatmap");
//heat.setLatLngs([]);
2016-04-01 18:31:07 +08:00
//}
//document.getElementById("heat").style.display = 'none';
var popped = false;
var popmark = null;
map.on('popupopen', function(e) {
popped = true;
popmark = e.popup._source;
popid = e.popup.dname;
});
map.on('popupclose', function(e) {
popped = false;
});
map.on('overlayadd', function(e) {
2016-06-06 01:37:17 +08:00
if (typeof overlays[e.name].bringToFront === "function") {
overlays[e.name].bringToFront();
}
2016-04-01 18:31:07 +08:00
if (e.name == "satellite") {
overlays["satellite"].bringToBack();
}
if (e.name == "heatmap") { // show heatmap button when it's layer is added.
//document.getElementById("heat").style.display = 'block';
clrHeat.addTo(map);
}
if (e.name == "day/night") {
//console.log("add daynight");
layers["_daynight"].addLayer(L.terminator());
}
if (e.name == "drawing") {
2018-02-01 06:54:03 +08:00
overlays["drawing"].bringToFront();
2018-10-13 06:58:20 +08:00
// And the actual draw controls
map.addControl(drawControl);
// Add the color change button
//colorControl.addTo(map);
2016-04-01 18:31:07 +08:00
}
2017-09-06 23:00:37 +08:00
ws.send(JSON.stringify({action:"addlayer", name:e.name}));
2016-04-01 18:31:07 +08:00
});
map.on('overlayremove', function(e) {
if (e.name == "heatmap") { // hide heatmap button when it's layer is removed.
//document.getElementById("heat").style.display = 'none';
clrHeat.removeFrom(map);
}
if (e.name == "day/night") {
//console.log("del daynight");
layers["_daynight"].clearLayers();
}
if (e.name == "drawing") {
2018-10-13 06:58:20 +08:00
map.removeControl(colorControl);
2016-04-01 18:31:07 +08:00
map.removeControl(drawControl);
}
//else console.log("layer del :",e.name);
2017-09-06 23:00:37 +08:00
ws.send(JSON.stringify({action:"dellayer", name:e.name}));
2016-04-01 18:31:07 +08:00
});
map.on('baselayerchange', function(e) {
//console.log("base layer now :",e.name);
baselayername = e.name;
2017-09-06 23:00:37 +08:00
ws.send(JSON.stringify({action:"layer", name:e.name}));
2016-04-01 18:31:07 +08:00
});
2016-06-27 18:55:30 +08:00
function showMapCurrentZoom() {
2018-06-12 00:08:26 +08:00
console.log("zoom:",map.getZoom(),". clusterAt:",clusterAt);
2016-06-27 18:55:30 +08:00
for (var l in layers) {
if (layers[l].hasOwnProperty("_zoom")) {
if (map.getZoom() >= clusterAt) {
layers[l].disableClustering();
}
else {
layers[l].enableClustering();
}
}
}
2016-04-01 18:31:07 +08:00
setTimeout( function() {
for (var key in markers) {
if (polygons[key]) {
var vis = layers[markers[key].lay].getVisibleParent(markers[key]);
if ((vis) & & (vis.hasOwnProperty("lay"))) {
polygons[key].setStyle({opacity:1});
}
else {
polygons[key].setStyle({opacity:0});
}
polygons[key].redraw();
}
}
},750);
2016-06-27 18:55:30 +08:00
}
map.on('zoomend', function() {
showMapCurrentZoom();
2016-04-01 18:31:07 +08:00
});
//map.on('contextmenu', function(e) {
2017-09-06 23:00:37 +08:00
// ws.send(JSON.stringify({action:"rightclick", lat:e.latlng.lat.toFixed(5), lon:e.latlng.lng.toFixed(5)}));
2016-04-01 18:31:07 +08:00
//});
2018-10-14 05:42:52 +08:00
var rightmenuMap = L.popup({keepInView:true, minWidth:250}).setContent("< input type = 'text' id = 'rinput' onkeydown = 'if (event.keyCode == 13) addThing();' placeholder = 'name (,icon, layer, colour)' / > ");
2016-04-01 18:31:07 +08:00
var rclk;
var addThing = function() {
var thing = document.getElementById('rinput').value;
2018-06-07 01:13:50 +08:00
//console.log(thing);
2016-04-01 18:31:07 +08:00
map.closePopup();
var bits = thing.split(",");
var icon = (bits[1] || "circle").trim();
2018-08-21 21:45:43 +08:00
var lay = (bits[2] || "drawing").trim();
var colo = (bits[3] || "#910000").trim();
2018-10-14 05:42:52 +08:00
var drag = true;
var regi = /^[S,G,E,I,O][A-Z]{4}.*/; // if it looks like a SIDC code
var d;
if (regi.test(icon)) {
icon = (icon+"------------").substr(0,12);
d = {name:bits[0].trim(),layer:lay,SIDC:icon,draggable:drag,lat:rclk.lat,lon:rclk.lng};
}
else {
d = {name:bits[0].trim(),layer:lay,icon:icon,iconColor:colo,draggable:drag,lat:rclk.lat,lon:rclk.lng};
}
2016-04-01 18:31:07 +08:00
map.addLayer(layers[lay]);
2018-10-14 05:42:52 +08:00
setMarker(d);
d.action = "point";
ws.send(JSON.stringify(d));
2016-04-01 18:31:07 +08:00
}
// allow double right click to zoom out
2016-06-15 19:57:31 +08:00
// single right click opens a message window that sends to the socket.
2016-04-01 18:31:07 +08:00
var rclicked = false;
var rtout = null;
map.on('contextmenu', function(e) {
if (rclicked) {
rclicked = false;
clearTimeout(rtout);
map.zoomOut();
}
else {
rclicked = true;
rtout = setTimeout( function() {
rclicked = false;
rclk = e.latlng;
rightmenuMap.setLatLng(e.latlng);
map.openPopup(rightmenuMap);
setTimeout( function() {
document.getElementById('rinput').focus();
}, 200);
}, 300);
}
});
function onLocationFound(e) {
2016-06-06 01:37:17 +08:00
var radius = e.accuracy;
2016-04-01 18:31:07 +08:00
//L.marker(e.latlng).addTo(map).bindPopup("You are within " + radius + " meters from this point").openPopup();
2016-06-15 19:57:31 +08:00
L.circle(e.latlng, radius, {color:"cyan", weight:4, opacity:0.8, fill:false, clickable:false}).addTo(map);
if (e.hasOwnProperty("heading")) {
var lengthAsDegrees = e.speed * 60 / 110540;
var ya = e.latlng.lat + Math.sin((90-e.heading)/180*Math.PI)*lengthAsDegrees*Math.cos(e.latlng.lng/180*Math.PI);
var xa = e.latlng.lng + Math.cos((90-e.heading)/180*Math.PI)*lengthAsDegrees;
var lla = new L.LatLng(ya,xa);
L.polygon([ e.latlng, lla ], {color:"cyan", weight:3, opacity:0.8, clickable:false}).addTo(map);
}
2017-09-06 23:00:37 +08:00
ws.send(JSON.stringify({action:"point", lat:e.latlng.lat.toFixed(5), lon:e.latlng.lng.toFixed(5), point:"self", bearing:e.heading, speed:(e.speed*3.6 || undefined)}));
2016-04-01 18:31:07 +08:00
}
function onLocationError(e) { console.log(e.message); }
map.on('locationfound', onLocationFound);
map.on('locationerror', onLocationError);
2016-06-15 19:57:31 +08:00
2016-04-01 18:31:07 +08:00
// Add all the base layer maps
// Use this for OSM online maps
2018-07-01 23:34:23 +08:00
var osmUrl='https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png';
//var osmUrl='https://{s}.tile.openstreetmap.fr/hot/{z}/{x}/{y}.png';
2016-04-01 18:31:07 +08:00
var osmAttrib='Map data © OpenStreetMap contributors';
2018-06-14 00:35:43 +08:00
var osmg = new L.TileLayer.Grayscale(osmUrl, {attribution:osmAttrib, maxNativeZoom:19, maxZoom:20});
2016-04-01 18:31:07 +08:00
basemaps["OSM grey"] = osmg;
2018-06-14 00:35:43 +08:00
var osm = new L.TileLayer(osmUrl, {attribution:osmAttrib, maxNativeZoom:19, maxZoom:20});
2016-04-01 18:31:07 +08:00
basemaps["OSM"] = osm;
2018-07-01 23:34:23 +08:00
// Extra Leaflet map layers from https://leaflet-extras.github.io/leaflet-providers/preview/
var Esri_WorldStreetMap = L.tileLayer('https://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer/tile/{z}/{y}/{x}', {
2018-06-14 00:35:43 +08:00
attribution: 'Tiles © Esri', maxNativeZoom:19, maxZoom:20
2016-04-01 18:31:07 +08:00
});
basemaps["Esri"] = Esri_WorldStreetMap;
2018-07-01 23:34:23 +08:00
var Esri_WorldImagery = L.tileLayer('https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}', {
2018-06-14 00:35:43 +08:00
attribution:'Tiles © Esri', maxNativeZoom:19, maxZoom:20
2016-04-01 18:31:07 +08:00
});
2016-06-02 00:19:04 +08:00
basemaps["Esri Satellite"] = Esri_WorldImagery;
2016-04-01 18:31:07 +08:00
2018-07-01 23:34:23 +08:00
var Esri_WorldShadedRelief = L.tileLayer('https://server.arcgisonline.com/ArcGIS/rest/services/World_Shaded_Relief/MapServer/tile/{z}/{y}/{x}', {
2016-11-22 16:21:56 +08:00
attribution: 'Tiles © Esri',
2018-06-14 00:35:43 +08:00
maxNativeZoom:13
2016-04-01 18:31:07 +08:00
});
basemaps["Esri Terrain"] = Esri_WorldShadedRelief;
2018-07-01 23:34:23 +08:00
var Esri_OceanBasemap = L.tileLayer('https://server.arcgisonline.com/ArcGIS/rest/services/Ocean_Basemap/MapServer/tile/{z}/{y}/{x}', {
2016-11-22 16:21:56 +08:00
attribution: 'Tiles © Esri',
2018-06-14 00:35:43 +08:00
maxNativeZoom:10
2016-04-01 18:31:07 +08:00
});
basemaps["Esri Ocean"] = Esri_OceanBasemap;
2018-07-01 23:34:23 +08:00
// var OpenMapSurfer_Roads = L.tileLayer('https://korona.geog.uni-heidelberg.de/tiles/roads/x={x}& y={y}& z={z}', {
2018-06-07 01:13:50 +08:00
// maxZoom: 18,
2018-07-01 23:34:23 +08:00
// attribution: 'Imagery from < a href = "https://giscience.uni-hd.de/" > University of Heidelberg< / a > — Map data © < a href = "https://www.openstreetmap.org/copyright" > OpenStreetMap< / a > '
2018-06-07 01:13:50 +08:00
// });
// basemaps["Mapsurfer"] = OpenMapSurfer_Roads;
2016-04-01 18:31:07 +08:00
2018-07-01 23:34:23 +08:00
// var MapQuestOpen_OSM = L.tileLayer('https://otile{s}.mqcdn.com/tiles/1.0.0/{type}/{z}/{x}/{y}.{ext}', {
2016-07-24 18:57:22 +08:00
// type: 'map',
// ext: 'jpg',
2018-07-01 23:34:23 +08:00
// attribution: 'Tiles Courtesy of < a href = "https://www.mapquest.com/" > MapQuest< / a > — Map data © < a href = "https://www.openstreetmap.org/copyright" > OpenStreetMap< / a > ',
2016-07-24 18:57:22 +08:00
// subdomains: '1234',
// maxNativeZoom: 17
// });
//basemaps["MapQuest OSM"] = MapQuestOpen_OSM;
2016-04-01 18:31:07 +08:00
2018-07-01 23:34:23 +08:00
var Esri_NatGeoWorldMap = L.tileLayer('https://server.arcgisonline.com/ArcGIS/rest/services/NatGeo_World_Map/MapServer/tile/{z}/{y}/{x}', {
2016-11-22 16:21:56 +08:00
attribution: 'Tiles © Esri',
2018-06-14 00:35:43 +08:00
maxNativeZoom:12
2016-04-01 18:31:07 +08:00
});
basemaps["Nat Geo"] = Esri_NatGeoWorldMap;
2018-07-01 23:34:23 +08:00
var NLS_OS_opendata = L.tileLayer('https://geo.nls.uk/maps/opendata/{z}/{x}/{y}.png', {
attribution: '< a href = "https://geo.nls.uk/maps/" > National Library of Scotland Historic Maps< / a > ',
2016-04-01 18:31:07 +08:00
bounds: [[49.6, -12], [61.7, 3]],
2018-06-14 00:35:43 +08:00
minZoom:1, maxNativeZoom:18, maxZoom:18,
2016-04-01 18:31:07 +08:00
subdomains: '0123'
});
basemaps["UK OS Opendata"] = NLS_OS_opendata;
2018-10-02 02:24:58 +08:00
var HikeBike_HikeBike = L.tileLayer('http://{s}.tiles.wmflabs.org/hikebike/{z}/{x}/{y}.png', {
maxZoom: 19,
attribution: '© < a href = "http://www.openstreetmap.org/copyright" > OpenStreetMap< / a > '
});
basemaps["Hike Bike"] = HikeBike_HikeBike;
2018-07-01 23:34:23 +08:00
var NLS_OS_1919_1947 = L.tileLayer( 'https://nls-{s}.tileserver.com/nls/{z}/{x}/{y}.jpg', {
attribution: 'Historical Maps Layer, from < a href = "https://maps.nls.uk/projects/api/" > NLS Maps< / a > ',
2016-05-27 05:12:56 +08:00
bounds: [[49.6, -12], [61.7, 3]],
2018-06-14 00:35:43 +08:00
minZoom:1, maxZoom:18,
2016-05-27 05:12:56 +08:00
subdomains: '0123'
});
basemaps["UK OS 1919-47"] = NLS_OS_1919_1947;
2018-07-01 23:34:23 +08:00
//var NLS_OS_1900 = L.tileLayer('https://nls-{s}.tileserver.com/NLS_API/{z}/{x}/{y}.jpg', {
var NLS_OS_1900 = L.tileLayer('https://nls-{s}.tileserver.com/fpsUZbzrfb5d/{z}/{x}/{y}.jpg', {
attribution: '< a href = "https://geo.nls.uk/maps/" > National Library of Scotland Historic Maps< / a > ',
2018-06-12 00:08:26 +08:00
bounds: [[49.6, -12], [61.7, 3]],
2018-06-14 00:35:43 +08:00
minZoom:1, maxNativeZoom:19, maxZoom:20,
2018-06-12 00:08:26 +08:00
subdomains: '0123'
});
basemaps["UK OS 1900"] = NLS_OS_1900;
2016-04-01 18:31:07 +08:00
2018-07-01 23:34:23 +08:00
//var CartoPos = L.tileLayer('https://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png', {
// attribution: '© < a href = "https://www.openstreetmap.org/copyright" > OpenStreetMap< / a > contributors, © < a href = "https://cartodb.com/attributions" > CartoDB< / a > '
2016-07-24 18:57:22 +08:00
//});
2016-04-01 18:31:07 +08:00
//basemaps["CartoDB Light"] = CartoPos;
2018-06-07 01:13:50 +08:00
// Terrain map by Stamen Design
basemaps["Terrain"] = new L.StamenTileLayer('terrain');
2016-04-01 18:31:07 +08:00
2016-05-27 05:12:56 +08:00
// Nice watercolour based maps by Stamen Design
2018-06-07 01:13:50 +08:00
basemaps["Watercolor"] = new L.StamenTileLayer('watercolor');
2016-05-27 05:12:56 +08:00
2018-10-13 06:58:20 +08:00
2016-04-01 18:31:07 +08:00
// Now add the overlays
2018-10-13 06:58:20 +08:00
// Add the countries (world-110m) for offline use
var customTopoLayer = L.geoJson(null, {style: {color:"blue", weight:2, fillColor:"#cf6", fillOpacity:0.04}});
layers["_countries"] = omnivore.topojson('images/world-50m-flat.json',null,customTopoLayer);
overlays["countries"] = layers["_countries"];
2016-04-01 18:31:07 +08:00
// Add the day/night overlay
layers["_daynight"] = new L.LayerGroup();
overlays["day/night"] = layers["_daynight"];
// Add the heatmap layer
var heat = L.heatLayer([], {radius:60, gradient:{0.2:'blue', 0.4:'lime', 0.6:'red', 0.8:'yellow', 1:'white'}});
2017-11-02 01:16:58 +08:00
layers["_heat"] = new L.LayerGroup().addLayer(heat);
overlays["heatmap"] = layers["_heat"];
2016-04-01 18:31:07 +08:00
// Add the drawing layer for fun...
2017-11-02 01:16:58 +08:00
layers["_drawing"] = new L.FeatureGroup();
overlays["drawing"] = layers["_drawing"];
2016-04-01 18:31:07 +08:00
var drawControl = new L.Control.Draw({
draw: {
polyline: { shapeOptions: { clickable:false } },
marker: false,
circle: false,
//circle: { shapeOptions: { clickable:false } },
rectangle: { shapeOptions: { clickable:true } },
polygon: { shapeOptions: { clickable:true } },
},
edit: {
2017-11-02 01:16:58 +08:00
featureGroup: layers["_drawing"],
2016-04-01 18:31:07 +08:00
remove: true,
edit: false
}
});
map.on('draw:created', function (e) {
var type = e.layerType;
var layer = e.layer;
//console.log(type, layer._latlngs);
//console.log(JSON.stringify(layer.toGeoJSON()));
2017-09-06 23:00:37 +08:00
ws.send(JSON.stringify({action:"draw",type:type, points:layer._latlngs}));
2017-11-02 01:16:58 +08:00
layers["_drawing"].addLayer(layer);
2016-04-01 18:31:07 +08:00
});
2016-10-19 05:37:07 +08:00
overlays["buildings"] = new OSMBuildings(map).load();
2018-06-01 00:32:29 +08:00
map.removeLayer(overlays["buildings"]); // Hide it at start
2016-10-19 05:37:07 +08:00
2018-10-02 02:24:58 +08:00
// Add Roads
overlays["roads"] = L.tileLayer('https://{s}.tile.openstreetmap.se/hydda/roads_and_labels/{z}/{x}/{y}.png', {
maxZoom: 18,
attribution: 'Tiles courtesy of < a href = "http://openstreetmap.se/" target = "_blank" > OpenStreetMap Sweden< / a > — Map data © < a href = "http://www.openstreetmap.org/copyright" > OpenStreetMap< / a > ',
opacity: 0.8
});
// Add Railways
overlays["railways"] = L.tileLayer('https://{s}.tiles.openrailwaymap.org/standard/{z}/{x}/{y}.png', {
maxZoom: 19,
attribution: 'Map data: © < a href = "http://www.openstreetmap.org/copyright" > OpenStreetMap< / a > | Map style: © < a href = "https://www.OpenRailwayMap.org" > OpenRailwayMap< / a > (< a href = "https://creativecommons.org/licenses/by-sa/3.0/" > CC-BY-SA< / a > )'
});
// Add Public Transport (Buses)
overlays["public transport"] = L.tileLayer('http://openptmap.org/tiles/{z}/{x}/{y}.png', {
maxZoom: 17,
attribution: 'Map data: © < a href = "http://www.openptmap.org" > OpenPtMap< / a > contributors'
});
// Add the OpenSea markers layer
overlays["ship nav"] = L.tileLayer('https://tiles.openseamap.org/seamark/{z}/{x}/{y}.png', {
maxZoom: 19,
attribution: 'Map data: © < a href = "https://www.openseamap.org" > OpenSeaMap< / a > contributors'
});
2016-04-01 18:31:07 +08:00
if ( window.localStorage.hasOwnProperty("lastlayer") ) {
if ( basemaps[window.localStorage.getItem("lastlayer")] ) {
baselayername = window.localStorage.getItem("lastlayer");
}
}
basemaps[baselayername].addTo(map);
// Layer control based on select box rather than radio buttons.
//var layercontrol = L.control.selectLayers(basemaps, overlays).addTo(map);
2017-10-11 06:51:18 +08:00
layercontrol = L.control.layers(basemaps, overlays);
// Add the layers control widget
if (!inIframe) { layercontrol.addTo(map); }
else { showLayerMenu = false;}
2016-04-01 18:31:07 +08:00
// Delete a marker (and notify websocket)
var delMarker = function(dname) {
if (typeof polygons[dname] != "undefined") {
2017-06-25 18:04:47 +08:00
layers[polygons[dname].lay].removeLayer(polygons[dname]);
2016-04-01 18:31:07 +08:00
delete polygons[dname];
}
2018-06-07 01:13:50 +08:00
if (typeof polygons[dname+"_"] != "undefined") {
layers[polygons[dname+"_"].lay].removeLayer(polygons[dname+"_"]);
delete polygons[dname+"_"];
}
2016-04-01 18:31:07 +08:00
if (typeof markers[dname] != "undefined") {
layers[markers[dname].lay].removeLayer(markers[dname]);
2018-06-07 01:13:50 +08:00
map.removeLayer(markers[dname]);
2016-04-01 18:31:07 +08:00
delete markers[dname];
}
2018-06-07 01:13:50 +08:00
ws.send(JSON.stringify({action:"delete", name:dname}));
2016-04-01 18:31:07 +08:00
map.closePopup();
}
// the MAIN add something to map function
function setMarker(data) {
2018-06-07 01:13:50 +08:00
//console.log("DATA",typeof data, data);
2016-04-01 18:31:07 +08:00
var ll;
2017-03-18 17:20:53 +08:00
var lli = null;
2016-04-01 18:31:07 +08:00
var stay = popped;
2017-06-25 18:06:31 +08:00
var opt = {};
opt.color = data.color || "#910000";
opt.fillColor = data.fillColor || "#910000";
opt.stroke = (data.hasOwnProperty("stroke")) ? data.stroke : true;
opt.weight = data.weight || 2;
opt.opacity = data.opacity || 1;
opt.fillOpacity = data.fillOpacity || 0.2;
opt.clickable = (data.hasOwnProperty("clickable")) ? data.clickable : false;
opt.fill = (data.hasOwnProperty("fill")) ? data.fill : true;
2016-04-01 18:31:07 +08:00
2018-05-29 16:04:32 +08:00
// Replace building
if (data.hasOwnProperty("building")) {
if ((data.building === "") & & layers.hasOwnProperty("buildings")) {
map.removeLayer(layers["buildings"]);
layercontrol._update();
layers["buildings"] = overlays["buildings"].set("");
return;
}
//layers["buildings"] = new OSMBuildings(map).set(data.building);
layers["buildings"] = overlays["buildings"].set(data.building);
map.addLayer(layers["buildings"]);
return;
}
2017-11-02 01:16:58 +08:00
var lay = data.layer || "unknown";
2016-04-01 18:31:07 +08:00
if (typeof layers[lay] == "undefined") { // add layer if if doesn't exist
2018-06-07 01:13:50 +08:00
//layers[lay] = new L.LayerGroup();
2016-06-27 18:55:30 +08:00
layers[lay] = new L.MarkerClusterGroup({
maxClusterRadius:50,
spiderfyDistanceMultiplier:1.8,
2018-06-07 01:13:50 +08:00
disableClusteringAtZoom:clusterAt
2016-06-27 18:55:30 +08:00
//zoomToBoundsOnClick:false
2018-06-07 01:13:50 +08:00
});
2016-04-01 18:31:07 +08:00
overlays[lay] = layers[lay];
2018-10-04 23:16:08 +08:00
if (showLayerMenu !== false) {
layercontrol.addOverlay(layers[lay],lay);
}
2018-06-07 01:13:50 +08:00
map.addLayer(overlays[lay]);
2018-06-12 00:08:26 +08:00
//console.log("ADDED LAYER",lay,layers);
2016-04-01 18:31:07 +08:00
}
2018-06-07 01:13:50 +08:00
if (typeof markers[data.name] != "undefined") {
try {layers[lay].removeLayer(markers[data.name]); }
catch(e) { console.log("OOPS"); }
}
2016-04-01 18:31:07 +08:00
if (typeof polygons[data.name] != "undefined") { layers[lay].removeLayer(polygons[data.name]); }
if (data.deleted) { // remove markers we are told to
delMarker(data.name);
}
2016-06-06 01:37:17 +08:00
else if (data.hasOwnProperty("line") & & Array.isArray(data.line)) {
2017-06-25 18:06:31 +08:00
delete opt.fill;
2017-06-26 23:19:05 +08:00
if (!data.hasOwnProperty("weight")) { opt.weight = 3; } //Standard settings different for lines
if (!data.hasOwnProperty("opacity")) { opt.opacity = 0.8; }
2017-06-25 18:06:31 +08:00
var polyln = L.polyline(data.line, opt);
2017-06-26 23:19:05 +08:00
if (opt.clickable) { polyln.bindPopup(data.name); }
2016-06-06 01:37:17 +08:00
polygons[data.name] = polyln;
2017-06-25 18:04:47 +08:00
polygons[data.name].lay = lay;
2017-09-06 23:00:37 +08:00
layers[lay].addLayer(polygons[data.name]);
2016-06-06 01:37:17 +08:00
}
else if (data.hasOwnProperty("area") & & Array.isArray(data.area)) {
2017-06-25 18:06:31 +08:00
var polyarea = L.polygon(data.area, opt);
2017-06-26 23:19:05 +08:00
if (opt.clickable) { polyarea.bindPopup(data.name); }
2016-06-06 01:37:17 +08:00
polygons[data.name] = polyarea;
2017-06-25 18:04:47 +08:00
polygons[data.name].lay = lay;
2017-09-06 23:00:37 +08:00
layers[lay].addLayer(polygons[data.name]);
2016-04-01 18:31:07 +08:00
}
2016-05-08 18:07:09 +08:00
else if (data.hasOwnProperty("sdlat") & & data.hasOwnProperty("sdlon")) {
2017-06-26 23:19:05 +08:00
if (!data.hasOwnProperty("iconColor")) { opt.color = "blue"; } //different standard Color Settings
if (!data.hasOwnProperty("fillColor")) { opt.fillColor = "blue"; }
2017-06-25 18:06:31 +08:00
delete opt.clickable;
var ellipse = L.ellipse(new L.LatLng((data.lat*1), (data.lon*1)), [200000*data.sdlon*Math.cos(data.lat*Math.PI/180), 200000*data.sdlat], 0, opt);
if (data.clickable != false) {
ellipse.on('click', function(e) {
var popup = L.popup()
.setLatLng(new L.LatLng((data.lat*1), (data.lon*1)))
.setContent('< p > < b > '+data.name+'< / b > < br / > lat : '+data.lat+'< br / > lon : '+data.lon+'< / p > ')
.openOn(map);
});
}
2016-05-08 18:07:09 +08:00
polygons[data.name] = ellipse;
2017-06-25 18:04:47 +08:00
polygons[data.name].lay = lay;
2016-05-08 18:07:09 +08:00
layers[lay].addLayer(ellipse);
}
2016-04-01 18:31:07 +08:00
else {
2016-11-14 04:27:12 +08:00
if (data.hasOwnProperty("radius")) {
if (data.hasOwnProperty("lat") & & data.hasOwnProperty("lon")) {
2017-06-25 18:06:31 +08:00
var polycirc = L.circle(new L.LatLng((data.lat*1), (data.lon*1)), data.radius*1, opt);
2017-06-26 23:19:05 +08:00
if (opt.clickable) { polycirc.bindPopup(data.name); }
2016-11-14 04:27:12 +08:00
polygons[data.name] = polycirc;
2017-06-25 18:04:47 +08:00
polygons[data.name].lay = lay;
2016-11-14 04:27:12 +08:00
layers[lay].addLayer(polycirc);
}
}
2016-04-01 18:31:07 +08:00
//console.log("handling",data.name);
if (typeof data.coordinates == "object") { ll = new L.LatLng(data.coordinates[1],data.coordinates[0]); }
2017-05-03 02:46:48 +08:00
else if (data.hasOwnProperty("position") & & data.position.hasOwnProperty("lat") & & data.position.hasOwnProperty("lon")) {
data.lat = data.position.lat*1;
data.lon = data.position.lon*1;
data.alt = data.position.alt;
if (parseFloat(data.position.alt) == data.position.alt) { data.alt = data.position.alt + " m"; }
delete data.position;
ll = new L.LatLng((data.lat*1), (data.lon*1));
}
2016-06-15 19:57:31 +08:00
else if (data.hasOwnProperty("lat") & & data.hasOwnProperty("lon")) { ll = new L.LatLng((data.lat*1), (data.lon*1)); }
else if (data.hasOwnProperty("latitude") & & data.hasOwnProperty("longitude")) { ll = new L.LatLng((data.latitude*1), (data.longitude*1)); }
else { console.log("No location:",data); return; }
2017-05-03 02:46:48 +08:00
2017-03-18 17:20:53 +08:00
// Adding new L.LatLng object (lli) when optional intensity value is defined. Only for use in heatmap layer
if (typeof data.coordinates == "object") { lli = new L.LatLng(data.coordinates[2],data.coordinates[1],data.coordinates[0]); }
2017-03-18 17:50:26 +08:00
else if (data.hasOwnProperty("lat") & & data.hasOwnProperty("lon") & & data.hasOwnProperty("intensity")) { lli = new L.LatLng((data.lat*1), (data.lon*1), (data.intensity*1)); }
2017-03-18 17:20:53 +08:00
else if (data.hasOwnProperty("latitude") & & data.hasOwnProperty("longitude") & & data.hasOwnProperty("intensity")) { lli = new L.LatLng((data.latitude*1), (data.longitude*1), (data.intensity*1)); }
else { lli = ll }
2016-04-01 18:31:07 +08:00
var words="< b > "+data.name+"< / b > < br / > ";
2017-06-26 23:19:05 +08:00
// Create the icons... handle plane, car, ship, wind, earthquake as specials
2018-07-09 20:32:18 +08:00
var marker, myMarker;
2016-05-19 06:26:08 +08:00
var icon, q;
2018-08-21 21:45:43 +08:00
var drag = false;
if (data.draggable === true) { drag = true; }
2017-07-13 00:59:56 +08:00
//console.log("ICON",data.icon);
2016-04-01 18:31:07 +08:00
if (data.icon === "ship") {
marker = L.boatMarker(ll, {
title: data.name,
color: (data.iconColor || "blue")
});
2018-07-17 19:21:01 +08:00
marker.setHeading(parseFloat(data.hdg || data.bearing || "0"));
2018-07-01 23:34:23 +08:00
q = 'https://www.bing.com/images/search?q='+data.icon+'%20%2B"'+encodeURIComponent(data.name)+'"';
2016-04-01 18:31:07 +08:00
words += '< a href = \''+q+'\' target = "_thingpic" > Pictures< / a > < br > ';
}
else if (data.icon === "plane") {
data.iconColor = data.iconColor || "black";
if (data.hasOwnProperty("squawk")) { data.iconColor = "red"; }
2018-07-09 20:32:18 +08:00
icon = '< svg xmlns = "http://www.w3.org/2000/svg" xmlns:xlink = "http://www.w3.org/1999/xlink" x = "0px" y = "0px" width = "310px" height = "310px" viewBox = "0 0 310 310" > ';
2017-06-26 23:19:05 +08:00
icon += '< path d = "M134.875,19.74c0.04-22.771,34.363-22.771,34.34,0.642v95.563L303,196.354v35.306l-133.144-43.821v71.424l30.813,24.072v27.923l-47.501-14.764l-47.501,14.764v-27.923l30.491-24.072v-71.424L3,231.66v-35.306l131.875-80.409V19.74z" fill = "'+data.iconColor+'" / > < / svg > ';
2016-04-01 18:31:07 +08:00
var svgplane = "data:image/svg+xml;base64," + btoa(icon);
2018-07-17 19:21:01 +08:00
var dir = parseFloat(data.hdg || data.bearing || "0");
2016-05-19 06:26:08 +08:00
myMarker = L.divIcon({
2016-04-01 18:31:07 +08:00
className:"planeicon",
2017-06-26 23:19:05 +08:00
iconAnchor: [16, 16],
2018-08-21 21:45:43 +08:00
html:'< img src = "'+svgplane+'" style = "width:32px; height:32px; -webkit-transform:rotate('+dir+'deg); -moz-transform:rotate('+dir+'deg);" / > '
2016-04-01 18:31:07 +08:00
});
2018-08-21 21:45:43 +08:00
marker = L.marker(ll, {title:data.name, icon:myMarker, draggable:drag});
2018-07-01 23:34:23 +08:00
//q = 'https://www.bing.com/images/search?q='+data.icon+'%20'+encodeURIComponent(data.name);
2017-06-21 06:27:18 +08:00
//words += '< a href = \''+q+'\' target = "_thingpic" > Pictures< / a > < br > ';
2016-04-01 18:31:07 +08:00
}
2017-06-28 16:01:03 +08:00
else if (data.icon === "uav") {
data.iconColor = data.iconColor || "black";
if (data.hasOwnProperty("squawk")) { data.iconColor = "red"; }
2018-07-16 17:19:17 +08:00
icon = '< svg xmlns = "http://www.w3.org/2000/svg" xmlns:xlink = "http://www.w3.org/1999/xlink" viewBox = "0 0 100 100" > ';
2017-06-28 16:01:03 +08:00
icon+= '< path d = "M62 82h-8V64h36c0-5-4-9-9-9H54v-8c0-3 4-5 4-11.1 0-4.4-3.6-8-8-8-4.4 0-8 3.6-8 8 0 5.1 4 8.1 4 11.1V55h-27c-5 0-9 4-9 9h36v18H38c-2.4 0-5 2.3-5 5L50 92l17-5C67 84.3 64.4 82 62 82z" fill = "'+data.iconColor+'" / > < / svg > ';
var svguav = "data:image/svg+xml;base64," + btoa(icon);
2018-07-17 19:21:01 +08:00
var dir = parseFloat(data.hdg || data.bearing || "0");
2017-06-28 16:01:03 +08:00
myMarker = L.divIcon({
className:"uavicon",
iconAnchor: [16, 16],
html:'< img src = "'+svguav+'" style = "width:32px; height:32px; -webkit-transform:rotate('+dir+'deg); -moz-transform:rotate('+dir+'deg);" / > ',
});
2018-08-21 21:45:43 +08:00
marker = L.marker(ll, {title:data.name, icon:myMarker, draggable:drag});
2017-06-28 16:01:03 +08:00
}
2016-04-18 23:57:31 +08:00
else if (data.icon === "car") {
data.iconColor = data.iconColor || "black";
2018-07-09 20:32:18 +08:00
icon = '< svg xmlns = "http://www.w3.org/2000/svg" xmlns:xlink = "http://www.w3.org/1999/xlink" x = "0px" y = "0px" width = "47px" height = "47px" viewBox = "0 0 47 47" > ';
2017-06-26 23:19:05 +08:00
icon += '< path d = "M29.395,0H17.636c-3.117,0-5.643,3.467-5.643,6.584v34.804c0,3.116,2.526,5.644,5.643,5.644h11.759 c3.116,0,5.644-2.527,5.644-5.644V6.584C35.037,3.467,32.511,0,29.395,0z M34.05,14.188v11.665l-2.729,0.351v-4.806L34.05,14.188z M32.618,10.773c-1.016,3.9-2.219,8.51-2.219,8.51H16.631l-2.222-8.51C14.41,10.773,23.293,7.755,32.618,10.773z M15.741,21.713 v4.492l-2.73-0.349V14.502L15.741,21.713z M13.011,37.938V27.579l2.73,0.343v8.196L13.011,37.938z M14.568,40.882l2.218-3.336 h13.771l2.219,3.336H14.568z M31.321,35.805v-7.872l2.729-0.355v10.048L31.321,35.805z" fill = "'+data.iconColor+'" / > < / svg > ';
2016-04-18 23:57:31 +08:00
var svgcar = "data:image/svg+xml;base64," + btoa(icon);
2018-07-17 19:21:01 +08:00
var dir = parseFloat(data.hdg || data.bearing || "0");
2016-05-19 06:26:08 +08:00
myMarker = L.divIcon({
2016-04-18 23:57:31 +08:00
className:"caricon",
2017-06-26 23:19:05 +08:00
iconAnchor: [16, 16],
html:'< img src = "'+svgcar+'" style = "width:32px; height:32px; -webkit-transform:rotate('+dir+'deg); -moz-transform:rotate('+dir+'deg);" / > ',
});
2018-08-21 21:45:43 +08:00
marker = L.marker(ll, {title:data.name, icon:myMarker, draggable:drag});
2017-06-26 23:19:05 +08:00
}
else if (data.icon === "arrow") {
data.iconColor = data.iconColor || "black";
2018-07-16 17:19:17 +08:00
icon = '< svg xmlns = "http://www.w3.org/2000/svg" xmlns:xlink = "http://www.w3.org/1999/xlink" width = "32px" height = "32px" viewBox = "0 0 32 32" > ';
2017-06-26 23:19:05 +08:00
icon += '< path d = "m16.2 0.6l-10.9 31 10.7-11.1 10.5 11.1 -10.3-31z" fill = "'+data.iconColor+'" / > < / svg > ';
var svgarrow = "data:image/svg+xml;base64," + btoa(icon);
2018-07-17 19:21:01 +08:00
var dir = parseFloat(data.hdg || data.bearing || "0");
2017-06-26 23:19:05 +08:00
myMarker = L.divIcon({
className:"arrowicon",
iconAnchor: [16, 16],
html:"'< img src = '"+svgarrow+"' style = 'width:32px; height:32px; -webkit-transform:translate(0px,-16px) rotate("+dir+"deg); -moz-transform:translate(0px,-16px) rotate("+dir+"deg);' / > ",
2016-04-18 23:57:31 +08:00
});
2018-08-21 21:45:43 +08:00
marker = L.marker(ll, {title:data.name, icon:myMarker, draggable:drag});
2017-06-26 23:19:05 +08:00
}
else if (data.icon === "wind") {
data.iconColor = data.iconColor || "black";
2018-07-16 17:19:17 +08:00
icon = '< svg xmlns = "http://www.w3.org/2000/svg" xmlns:xlink = "http://www.w3.org/1999/xlink" width = "32px" height = "32px" viewBox = "0 0 32 32" > ';
2017-06-26 23:19:05 +08:00
icon += '< path d = "M16.7 31.7l7-6.9c0.4-0.4 0.4-1 0-1.4 -0.4-0.4-1-0.4-1.4 0l-5.3 5.2V17.3l6.7-6.6c0.2-0.2 0.3-0.5 0.3-0.7v-9c0-0.9-1.1-1.3-1.7-0.7l-6.3 6.2L9.7 0.3C9.1-0.3 8 0.1 8 1.1v8.8c0 0.3 0.1 0.6 0.3 0.8l6.7 6.6v11.3l-5.3-5.2c-0.4-0.4-1-0.4-1.4 0 -0.4 0.4-0.4 1 0 1.4l7 6.9c0.2 0.2 0.5 0.3 0.7 0.3C16.2 32 16.5 31.9 16.7 31.7zM10 9.6V3.4l5 4.9v6.2L10 9.6zM17 8.3l5-4.9v6.2l-5 4.9V8.3z" fill = "'+data.iconColor+'" / > < / svg > ';
var svgwind = "data:image/svg+xml;base64," + btoa(icon);
2018-07-17 19:21:01 +08:00
var dir = parseFloat(data.hdg || data.bearing || "0");
2017-06-26 23:19:05 +08:00
myMarker = L.divIcon({
className:"windicon",
iconAnchor: [16, 16],
html:'< img src = "'+svgwind+'" style = "width:32px; height:32px; -webkit-transform:rotate('+dir+'deg); -moz-transform:rotate('+dir+'deg);" / > ',
});
2018-08-21 21:45:43 +08:00
marker = L.marker(ll, {title:data.name, icon:myMarker, draggable:drag});
2016-04-18 23:57:31 +08:00
}
2017-05-15 20:55:22 +08:00
else if (data.icon === "satellite") {
data.iconColor = data.iconColor || "black";
2018-07-16 17:19:17 +08:00
icon = '< svg xmlns = "http://www.w3.org/2000/svg" xmlns:xlink = "http://www.w3.org/1999/xlink" viewBox = "0 0 100 100" > ';
2017-05-15 20:55:22 +08:00
icon += '< polygon points = "38.17 39.4 45.24 32.33 43.34 27.92 24.21 8.78 14.59 18.4 33.72 37.53" fill = "'+data.iconColor+'" / > ';
icon += '< path d = "M69.22 44.57L54.38 29.73c-1.1-1.1-2.91-1.1-4.01 0L35.53 44.57c-1.1 1.1-1.1 2.91 0 4.01l14.84 14.84c1.1 1.1 2.91 1.1 4.01 0l14.84-14.84C70.32 47.47 70.32 45.67 69.22 44.57z" fill = "'+data.iconColor+'" / > ';
icon += '< polygon points = "71.04 55.61 66.58 53.75 59.52 60.82 61.42 65.23 80.55 84.36 90.17 74.75" fill = "'+data.iconColor+'" / > ';
icon += '< path d = "M28.08 55.26l-6.05 0.59C23.11 68.13 32.78 77.94 45 79.22l0.59-6.05C36.26 72.15 28.89 64.66 28.08 55.26z" fill = "'+data.iconColor+'" / > ';
icon += '< path d = "M15.88 56.54L9.83 57.13c1.67 18.06 16.03 32.43 34.08 34.09l0.59-6.04C29.34 83.76 17.29 71.71 15.88 56.54z" fill = "'+data.iconColor+'" / > ';
icon += '< / svg > ';
2018-07-16 22:52:33 +08:00
var svgsat = "data:image/svg+xml;base64," + btoa(icon);
2017-05-15 20:55:22 +08:00
myMarker = L.divIcon({
className:"satelliteicon",
iconAnchor: [16, 16],
2018-07-16 22:52:33 +08:00
html:'< img src = "'+svgsat+'" style = "width:32px; height:32px;" / > ',
});
2018-08-21 21:45:43 +08:00
marker = L.marker(ll, {title:data.name, icon:myMarker, draggable:drag});
2018-07-16 22:52:33 +08:00
}
else if ((data.icon === "iss") || (data.icon === "ISS")) {
data.iconColor = data.iconColor || "black";
icon = '< svg xmlns = "http://www.w3.org/2000/svg" xmlns:xlink = "http://www.w3.org/1999/xlink" viewBox = "0 0 48 48" > ';
icon += '< path id = "iss" d = "m4.55 30 . 97l6 . 85-12 . 68 0 . 59 0 . 32 -6 . 85 12 . 68 4 . 27 2 . 3 6 . 85-12 . 68 0 . 49 0 . 27 -0 . 81 1 . 5c-0 . 26 0 . 48-0 . 07 1 . 1 0 . 44 1 . 37l5 . 09 2 . 75c0 . 5 0 . 27 1 . 12 0 . 1 1 . 38-0 . 39l0 . 81-1 . 5 0 . 72 0 . 39 -1 . 49 2 . 75c-0 . 41 0 . 76-0 . 38 1 . 58 0 . 08 1 . 82l4 . 61 2 . 49c0 . 45 0 . 24 1 . 15-0 . 18 1 . 56-0 . 94l1 . 49-2 . 75 0 . 69 0 . 37 -6 . 85 12 . 68 4 . 26 2 . 3 6 . 85-12 . 68 0 . 59 0 . 32 -6 . 85 12 . 69 4 . 26 2 . 3 14 . 46-26 . 78 -4 . 26-2 . 3 -6 . 88 12 . 74 -0 . 59-0 . 32 6 . 88-12 . 74 -4 . 26-2 . 3 -6 . 88 12 . 74 -0 . 69-0 . 37 1 . 49-2 . 75c0 . 41-0 . 76 ' ;
icon += '0.38-1.58-0.08-1.82l-1.4-0.75 0.5-0.92c1.02 0.17 2.09-0.32 2.62-1.3 0.67-1.23 0.22-2.76-0.99-3.42 -1.21-0.65-2.74-0.19-3.4 1.05 -0.53 0.98-0.35 2.14 0.35 2.9l-0.5 0.92 -1.8-0.97c-0.45-0.24-1.15 0.17-1.57 0.94l-1.49 2.75 -0.72-0.39 0.81-1.5c0.26-0.48 0.07-1.1-0.44-1.36l-5.09-2.75c-0.5-0.27-1.12-0.1-1.38 0.39l-0.81 1.5 -0.49-0.27 6.88-12.74 -4.26-2.3 -6.88 12.74 -0.59-0.32 6.88-12.74 -4.26-2.3 -14.46 26.78 4.26 2.3zm14.26-11.72c0.2-0.37 0.68-0.51 1.06-0.3l3.93 ';
icon += '2.12c0.39 0.21 0.54 0.68 0.34 1.05l-1.81 3.35c-0.2 0.37-0.68 0.51-1.06 0.3l-3.93-2.12c-0.38-0.21-0.53-0.68-0.33-1.05l1.81-3.35zm12.01-1.46c0.45-0.83 1.47-1.14 2.28-0.7 0.81 0.44 1.11 1.46 0.66 2.29 -0.44 0.83-1.47 1.14-2.28 0.7 -0.81-0.44-1.11-1.46-0.66-2.29zm-3.78 4.26c0.35-0.66 0.93-1.04 1.28-0.85l3.57 1.93c0.35 0.19 0.35 0.88-0.01 1.53l-3.19 5.91c-0.35 0.66-0.93 1.04-1.28 0.85l-3.56-1.92c-0.35-0.19-0.35-0.88 0.01-1.53l3.19-5.91zm0.19 7.49c-0.26 0.49-0.87 ';
icon += '0.67-1.36 0.41 -0.49-0.26-0.67-0.87-0.41-1.36 0.27-0.49 0.87-0.67 1.36-0.4 0.49 0.26 0.67 0.87 0.41 1.36zm-7.46-6.31c-0.26 0.49-0.87 0.67-1.36 0.41s-0.67-0.87-0.41-1.36c0.27-0.49 0.87-0.67 1.36-0.4s0.67 0.87 0.41 1.36zm2.32 1.25c-0.26 0.49-0.87 0.67-1.36 0.41 -0.49-0.26-0.67-0.87-0.41-1.36 0.27-0.49 0.87-0.67 1.36-0.41 0.49 0.26 0.67 0.87 0.41 1.36z" fill="'+data.iconColor+'"/>';
icon += '< / svg > ';
var svgiss = "data:image/svg+xml;base64," + btoa(icon);
myMarker = L.divIcon({
className:"issicon",
iconAnchor: [25, 25],
html:'< img src = "'+svgiss+'" style = "width:50px; height:50px;" / > ',
2017-05-15 20:55:22 +08:00
});
2018-08-21 21:45:43 +08:00
marker = L.marker(ll, {title:data.name, icon:myMarker, draggable:drag});
2017-05-15 20:55:22 +08:00
}
2016-06-03 16:11:48 +08:00
else if (data.icon === "locate") {
data.iconColor = data.iconColor || "cyan";
2018-07-09 20:32:18 +08:00
icon = '< svg xmlns = "http://www.w3.org/2000/svg" xmlns:xlink = "http://www.w3.org/1999/xlink" x = "0px" y = "0px" width = "468px" height = "468px" viewBox = "0 0 468 468" > ';
2016-06-03 16:11:48 +08:00
icon += '< polygon points = "32 32 104 32 104 0 0 0 0 104 32 104" fill = "'+data.iconColor+'" / > ';
icon += '< polygon points = "468 0 364 0 364 32 436 32 436 104 468 104" fill = "'+data.iconColor+'" / > ';
icon += '< polygon points = "0 468 104 468 104 436 32 436 32 364 0 364" fill = "'+data.iconColor+'" / > ';
icon += '< polygon points = "436 436 364 436 364 468 468 468 468 364 436 364" fill = "'+data.iconColor+'" / > ';
//icon += '< circle cx = "234" cy = "234" r = "22" fill = "'+data.iconColor+'" / > ';
icon += '< / svg > ';
var svglocate = "data:image/svg+xml;base64," + btoa(icon);
myMarker = L.divIcon({
className:"locateicon",
iconAnchor: [16, 16],
html:'< img src = "'+svglocate+'" style = "width:32px; height:32px;" / > ',
});
2018-08-21 21:45:43 +08:00
marker = L.marker(ll, {title:data.name, icon:myMarker, draggable:drag});
2016-06-03 16:11:48 +08:00
}
2016-04-01 18:31:07 +08:00
else if (data.icon === "friend") {
2018-08-21 21:45:43 +08:00
marker = L.marker(ll, { icon: L.divIcon({ className: 'circle f', iconSize: [20, 12] }), title: data.name, draggable:drag });
2016-04-01 18:31:07 +08:00
}
else if (data.icon === "hostile") {
2018-08-21 21:45:43 +08:00
marker = L.marker(ll, { icon: L.divIcon({ className: 'circle h', iconSize: [16, 16] }), title: data.name, draggable:drag });
2016-04-01 18:31:07 +08:00
}
else if (data.icon === "neutral") {
2018-08-21 21:45:43 +08:00
marker = L.marker(ll, { icon: L.divIcon({ className: 'circle n', iconSize: [16, 16] }), title: data.name, draggable:drag });
2016-04-01 18:31:07 +08:00
}
else if (data.icon === "unknown") {
2018-08-21 21:45:43 +08:00
marker = L.marker(ll, { icon: L.divIcon({ className: 'circle', iconSize: [16, 16] }), title: data.name, draggable:drag });
2016-04-01 18:31:07 +08:00
}
else if (data.icon === "danger") {
2018-08-21 21:45:43 +08:00
marker = L.marker(ll, { icon: L.divIcon({ className: 'up-triangle' }), title: data.name, draggable:drag });
2016-04-01 18:31:07 +08:00
}
else if (data.icon === "earthquake") {
2018-08-21 21:45:43 +08:00
marker = L.marker(ll, { icon: L.divIcon({ className: 'circle e', iconSize: [data.mag*5, data.mag*5] }), title: data.name, draggable:drag });
2016-04-01 18:31:07 +08:00
}
2018-06-01 00:32:29 +08:00
else if (data.hasOwnProperty("SIDC")) {
// "SIDC":"SFGPU------E***","name":"1.C2 komp","fullname":"1.C2 komp/FTS/INSS"
myMarker = new ms.Symbol( data.SIDC, { uniqueDesignation:data.name });
// Now that we have a symbol we can ask for the echelon and set the symbol size
var opts = data.options || {};
2018-06-01 05:50:50 +08:00
opts.size = opts.size || iconSz[myMarker.getProperties().echelon] || 30;
opts.size = opts.size * (opts.scale || 1);
2018-06-01 00:32:29 +08:00
myMarker = myMarker.setOptions(opts);
var myicon = L.icon({
2018-09-20 03:50:06 +08:00
iconUrl: myMarker.toDataURL(),
iconAnchor: [myMarker.getAnchor().x, myMarker.getAnchor().y],
className: "natoicon",
2018-06-01 00:32:29 +08:00
});
2018-08-21 21:45:43 +08:00
marker = L.marker(ll, { title:data.name, icon:myicon, draggable:drag });
2018-06-01 00:32:29 +08:00
}
2017-09-06 21:39:14 +08:00
else if (data.icon & & (data.icon.substr(0,3) === "fa-")) {
2017-07-13 00:59:56 +08:00
var col = data.iconColor || "#910000";
2018-10-05 05:39:42 +08:00
var imod = "";
if (data.icon.indexOf(" ") === -1) { imod = "fa-2x "; }
2017-07-13 00:59:56 +08:00
myMarker = L.divIcon({
2017-09-06 23:00:37 +08:00
className:"faicon",
2018-10-05 05:39:42 +08:00
html: '< center > < i class = "fa fa-fw '+imod+data.icon+'" style = "color:'+col+'" > < / i > < / center > ',
2017-09-06 23:00:37 +08:00
iconSize: [30, 30]
2017-07-13 00:59:56 +08:00
});
2018-08-21 21:45:43 +08:00
marker = L.marker(ll, {title:data.name, icon:myMarker, draggable:drag});
2017-07-13 00:59:56 +08:00
}
2016-04-01 18:31:07 +08:00
else {
2016-05-19 06:26:08 +08:00
myMarker = L.VectorMarkers.icon({
2016-04-01 18:31:07 +08:00
icon: data.icon || "circle",
markerColor: (data.iconColor || "#910000"),
prefix: 'fa',
iconColor: 'white'
});
2018-08-21 21:45:43 +08:00
marker = L.marker(ll, {title:data.name, icon:myMarker, draggable:drag});
2016-04-01 18:31:07 +08:00
}
2017-09-26 22:54:36 +08:00
// var createLabelIcon = function(labelText) {
// return L.marker(new L.LatLng(51.05, -1.35), {icon:L.divIcon({ html:labelText })});
// }
2018-08-21 21:45:43 +08:00
// send new position at end of move event if point is draggable
if (data.draggable === true) {
marker.name = data.name;
marker.icon = data.icon;
2018-10-14 05:42:52 +08:00
marker.iconColor = data.iconColor;
marker.SIDC = data.SIDC;
2018-08-21 21:45:43 +08:00
marker.on('dragend', function (e) {
2018-10-14 05:42:52 +08:00
ws.send(JSON.stringify({action:"move",name:marker.name,layer:marker.lay,icon:marker.icon,iconColor:marker.iconColor,SIDC:marker.SIDC,lat:parseFloat(marker.getLatLng().lat.toFixed(6)),lon:parseFloat(marker.getLatLng().lng.toFixed(6))}));
2018-08-21 21:45:43 +08:00
});
}
if (data.draggable) { delete data.draggable; }
2016-04-01 18:31:07 +08:00
// remove icon from list of properties, then add all others to popup
2018-06-01 05:50:50 +08:00
if (data.hasOwnProperty("SIDC") & & data.hasOwnProperty("options")) { delete data.options; }
2016-11-14 04:27:12 +08:00
if (data.hasOwnProperty("icon") || (!data.hasOwnProperty("radius"))) {
if (data.hasOwnProperty("icon")) { delete data.icon; }
if (data.hasOwnProperty("iconColor")) { delete data.iconColor; }
2017-03-21 00:05:40 +08:00
if (data.hasOwnProperty("photourl")) {
words += "< img src = \"" + data . photourl + " \ " style = \"width:100%; margin-top:10px ; \ " > ";
delete data.photourl;
}
if (data.hasOwnProperty("photoUrl")) {
words += "< img src = \"" + data . photoUrl + " \ " style = \"width:100%; margin-top:10px ; \ " > ";
delete data.photoUrl;
}
2017-12-14 06:16:09 +08:00
if (data.hasOwnProperty("videoUrl")) {
words += '< video controls autoplay > < source src = "'+data.videoUrl+'" type = "video/mp4" > Your browser does not support the video tag.< / video > ';
delete data.videoUrl;
}
2017-11-02 01:16:58 +08:00
if (data.hasOwnProperty("ttl")) { // save expiry time for this marker
if (data.ttl != 0) {
marker.ts = parseInt(Date.now()/1000) + Number(data.ttl);
}
delete data.ttl;
}
else if (maxage != 0) {
marker.ts = parseInt(Date.now()/1000) + Number(maxage);
}
2017-03-21 00:05:40 +08:00
if (data.hasOwnProperty("weblink")) {
if (typeof data.weblink === "string") {
words += "< b > < a href = '"+ data.weblink + "' target = '_new' > more information...< / a > < / b > < br / > ";
} else {
2018-06-18 04:47:47 +08:00
var tgt = data.weblink.target || "_new";
words += "< b > < a href = '"+ data.weblink.url + "' target = '"+ tgt + "' > " + data.weblink.name + "< / a > < / b > < br / > ";
2017-03-21 00:05:40 +08:00
}
delete data.weblink;
}
2018-07-01 23:34:23 +08:00
popped = stay;
2018-09-20 03:50:06 +08:00
if (data.hasOwnProperty("popped") & & (data.popped == true) ) {
2018-07-04 16:05:41 +08:00
popped = true;
popid = data.name;
2018-09-20 03:50:06 +08:00
delete data.popped;
2018-07-04 16:05:41 +08:00
}
2018-07-01 23:34:23 +08:00
// Add any remaining properties to the info box
2016-11-14 04:27:12 +08:00
for (var i in data) {
2017-06-21 06:27:18 +08:00
if ((i != "name") & & (i != "length")) {
2016-11-14 04:27:12 +08:00
if (typeof data[i] === "object") {
words += i +" : "+JSON.stringify(data[i])+"< br / > ";
} else {
words += i +" : "+data[i]+"< br / > ";
}
2016-04-01 18:31:07 +08:00
}
}
2018-09-20 03:50:06 +08:00
words = data.popup || words;
2017-12-14 06:16:09 +08:00
marker.bindPopup(words, {keepInView:true, minWidth:348});
2016-11-14 04:27:12 +08:00
marker._popup.dname = data.name;
marker.lay = lay; // and the layer it is on
var rightmenuMarker = L.popup().setContent("< b > "+data.name+"< / b > < br / > < button onclick = 'delMarker(\""+data.name+"\");' > Delete< / button > ");
marker.on('contextmenu', function(e) {
rightmenuMarker.setLatLng(e.latlng);
map.openPopup(rightmenuMarker);
});
2017-04-20 20:44:19 +08:00
if ((data.addtoheatmap !== "false") || (!data.hasOwnProperty("addtoheatmap"))) { // Added to give ability to control if points from active layer contribute to heatmap
if (heatAll || map.hasLayer(layers[lay])) { heat.addLatLng(lli); }
2017-03-18 17:20:53 +08:00
}
2016-11-14 04:27:12 +08:00
markers[data.name] = marker;
layers[lay].addLayer(marker);
}
2016-04-01 18:31:07 +08:00
if ((data.hdg != null) & & (data.bearing == null)) { data.bearing = data.hdg; delete data.hdg; }
if (data.bearing != null) { // if there is a heading
2018-07-17 19:21:01 +08:00
if (data.speed != null) { data.length = parseFloat(data.speed || "0") * 50; } // and a speed
2016-04-01 18:31:07 +08:00
if (data.length != null) {
if (polygons[data.name] != null) { map.removeLayer(polygons[data.name]); }
2016-06-15 19:57:31 +08:00
var x = ll.lng; // X coordinate
var y = ll.lat * 1; // Y coordinate
var ll1 = ll;
2018-07-17 19:21:01 +08:00
var angle = parseFloat(data.bearing);
var lengthAsDegrees = parseFloat(data.length || "0") / 110540; // metres in a degree..ish
2016-04-01 18:31:07 +08:00
var polygon = null;
if (data.accuracy != null) {
data.accuracy = Number(data.accuracy);
var y2 = y + Math.sin((90-angle+data.accuracy)/180*Math.PI)*lengthAsDegrees*Math.cos(y/180*Math.PI);
var x2 = x + Math.cos((90-angle+data.accuracy)/180*Math.PI)*lengthAsDegrees;
var ll2 = new L.LatLng(y2,x2);
var y3 = y + Math.sin((90-angle-data.accuracy)/180*Math.PI)*lengthAsDegrees*Math.cos(y/180*Math.PI);
var x3 = x + Math.cos((90-angle-data.accuracy)/180*Math.PI)*lengthAsDegrees;
var ll3 = new L.LatLng(y3,x3);
2016-06-06 01:37:17 +08:00
polygon = L.polygon([ ll1, ll2, ll3 ], {weight:2, color:'#f30', fillOpacity:0.06, clickable:false});
2016-04-01 18:31:07 +08:00
} else {
2016-06-06 01:37:17 +08:00
var ya = y + Math.sin((90-angle)/180*Math.PI)*lengthAsDegrees*Math.cos(y/180*Math.PI);
var xa = x + Math.cos((90-angle)/180*Math.PI)*lengthAsDegrees;
var lla = new L.LatLng(ya,xa);
polygon = L.polygon([ ll1, lla ], {weight:2, color:'#f30', clickable:false});
2016-04-01 18:31:07 +08:00
}
if (typeof layers[lay].getVisibleParent === 'function') {
var vis = layers[lay].getVisibleParent(marker);
if ((polygon !== null) & & (vis !== null) & & (!vis.hasOwnProperty("lay"))) {
polygon.setStyle({opacity:0});
}
polygons[data.name] = polygon;
2017-06-25 18:04:47 +08:00
polygons[data.name].lay = lay;
2016-04-01 18:31:07 +08:00
layers[lay].addLayer(polygon);
}
}
}
if (panit) {
map.setView(ll,map.getZoom());
}
2018-07-01 23:34:23 +08:00
if (popped) {
if (popid == data.name) { marker.openPopup(); }
else { popmark.openPopup(); }
}
2016-04-01 18:31:07 +08:00
}
}
function doCommand(cmd) {
2018-09-20 03:50:06 +08:00
// console.log("COMMAND",cmd);
2016-06-12 19:40:29 +08:00
// ignore server side initial command if client position already saved.
2018-06-07 06:45:06 +08:00
// if (cmd.hasOwnProperty("init") & & initialposition) {
// return;
// }
2017-11-02 01:16:58 +08:00
if (cmd.hasOwnProperty("clear")) {
doTidyUp(cmd.clear);
}
2016-11-22 16:21:56 +08:00
if (cmd.hasOwnProperty("panit")) {
if (cmd.panit === "true") { panit = true; }
else { panit = false; }
}
if (cmd.hasOwnProperty("showmenu")) {
if ((cmd.showmenu === "hide") & & (showUserMenu === true)) {
showUserMenu = false;
map.removeControl(menuButton);
}
else if ((cmd.showmenu === "show") & & (showUserMenu === false)) {
showUserMenu = true;
map.addControl(menuButton);
}
}
2017-10-11 06:51:18 +08:00
if (cmd.hasOwnProperty("showlayers")) {
if ((cmd.showlayers === "hide") & & (showLayerMenu === true)) {
showLayerMenu = false;
layercontrol.removeFrom(map);
}
else if ((cmd.showlayers === "show") & & (showLayerMenu === false)) {
showLayerMenu = true;
layercontrol = L.control.layers(basemaps, overlays).addTo(map);
}
}
2016-06-02 00:19:04 +08:00
var existsalready = false;
// Add a new base map layer
2016-04-01 18:31:07 +08:00
if (cmd.map & & cmd.map.hasOwnProperty("name") & & cmd.map.hasOwnProperty("url") & & cmd.map.hasOwnProperty("opt")) {
2018-06-27 03:42:24 +08:00
console.log("BASE",cmd.map);
2016-06-02 00:19:04 +08:00
if (basemaps.hasOwnProperty(cmd.map.name)) { existsalready = true; }
2017-04-20 20:44:19 +08:00
if (cmd.map.hasOwnProperty("wms")) { // special case for wms
console.log("New WMS:",cmd.map.name);
2017-05-03 02:46:48 +08:00
if (cmd.map.wms === "grey") {
basemaps[cmd.map.name] = L.tileLayer.graywms(cmd.map.url, cmd.map.opt);
}
else {
basemaps[cmd.map.name] = L.tileLayer.wms(cmd.map.url, cmd.map.opt);
}
2017-04-20 20:44:19 +08:00
}
else {
console.log("New Map:",cmd.map.name);
basemaps[cmd.map.name] = L.tileLayer(cmd.map.url, cmd.map.opt);
}
2017-10-11 06:51:18 +08:00
//if (!existsalready & & !inIframe) {
if (!existsalready) {
2016-06-02 00:19:04 +08:00
layercontrol.addBaseLayer(basemaps[cmd.map.name],cmd.map.name);
}
}
2018-02-01 06:54:03 +08:00
// Add a new geojson overlay layer
2018-01-03 16:31:02 +08:00
if (cmd.map & & cmd.map.hasOwnProperty("overlay") & & cmd.map.hasOwnProperty("geojson") ) {
2018-02-01 06:54:03 +08:00
if (overlays.hasOwnProperty(cmd.map.overlay)) {
map.removeLayer(overlays[cmd.map.overlay]);
existsalready = true;
}
2018-09-21 05:26:17 +08:00
var opt = cmd.map.opt || { style:function(feature) {
var st = { stroke:true, weight:2, fill:true };
if (feature.hasOwnProperty("properties")) {
st.color = feature.properties.color||feature.properties.roofColor||"black";
if (feature.properties.hasOwnProperty("color")) { delete feature.properties.color; }
if (feature.properties.hasOwnProperty("roofColor")) { delete feature.properties.roofColor; }
}
if (feature.hasOwnProperty("properties") & & feature.properties.hasOwnProperty('style')) {
if (feature.properties.style.hasOwnProperty('stroke')) {
st.color = feature.properties.style.stroke;
}
if (feature.properties.style.hasOwnProperty('stroke-width')) {
st.weight = feature.properties.style["stroke-width"];
}
if (feature.properties.style.hasOwnProperty('stroke-opacity')) {
st.opacity = feature.properties.style["stroke-opacity"];
}
if (feature.properties.style.hasOwnProperty('fill')) {
if (feature.properties.style.fill == "none") { st.fill = false; }
else { st.fillColor = feature.properties.style.fill; }
}
if (feature.properties.style.hasOwnProperty('fill-opacity')) {
st.fillOpacity = feature.properties.style["fill-opacity"];
}
}
delete feature.properties.style;
return st;
}};
opt.onEachFeature = function (f,l) {
2018-06-27 03:42:24 +08:00
l.bindPopup('< pre > '+JSON.stringify(f.properties,null,' ').replace(/[\{\}"]/g,'')+'< / pre > ');
}
overlays[cmd.map.overlay] = L.geoJson(cmd.map.geojson,opt);
if (!existsalready) {
layercontrol.addOverlay(overlays[cmd.map.overlay],cmd.map.overlay);
}
map.addLayer(overlays[cmd.map.overlay]);
if (cmd.map.hasOwnProperty("fit")) { map.fitBounds(overlays[cmd.map.overlay].getBounds()); }
}
2018-09-20 03:50:06 +08:00
// Add a new NVG XML overlay layer
if (cmd.map & & cmd.map.hasOwnProperty("overlay") & & cmd.map.hasOwnProperty("nvg") ) {
if (overlays.hasOwnProperty(cmd.map.overlay)) {
map.removeLayer(overlays[cmd.map.overlay]);
existsalready = true;
}
var parser = new NVG(cmd.map.nvg);
var geoj = parser.toGeoJSON();
overlays[cmd.map.overlay] = L.geoJson(geoj,{
style: function(feature) {
var st = { stroke:true, color:"black", weight:2, fill:true };
if (feature.hasOwnProperty("properties") & & feature.properties.hasOwnProperty('style')) {
if (feature.properties.style.hasOwnProperty('stroke')) {
st.color = feature.properties.style.stroke;
}
if (feature.properties.style.hasOwnProperty('stroke-width')) {
st.weight = feature.properties.style["stroke-width"];
}
if (feature.properties.style.hasOwnProperty('stroke-opacity')) {
st.opacity = feature.properties.style["stroke-opacity"];
}
if (feature.properties.style.hasOwnProperty('fill')) {
if (feature.properties.style.fill == "none") { st.fill = false; }
else { st.fillColor = feature.properties.style.fill; }
}
if (feature.properties.style.hasOwnProperty('fill-opacity')) {
st.fillOpacity = feature.properties.style["fill-opacity"];
}
}
return st;
}
});
if (!existsalready) {
layercontrol.addOverlay(overlays[cmd.map.overlay],cmd.map.overlay);
}
map.addLayer(overlays[cmd.map.overlay]);
if (cmd.map.hasOwnProperty("fit")) { map.fitBounds(overlays[cmd.map.overlay].getBounds()); }
}
2018-09-21 05:26:17 +08:00
var custIco = function() {
var customLayer = L.geoJson();
if (cmd.map.hasOwnProperty("icon")) {
var col = cmd.map.iconColor || "#910000";
var myMarker = L.divIcon({
className:"faicon",
html: '< center > < i class = "fa fa-fw '+cmd.map.icon+'" style = "color:'+col+'" > < / i > < / center > ',
iconSize: [15, 15],
});
customLayer = L.geoJson(null, {
pointToLayer: function(geoJsonPoint, latlng) {
return L.marker(latlng, {icon: myMarker, title: geoJsonPoint.properties.name});
}
});
}
return customLayer;
}
2018-06-27 03:42:24 +08:00
// Add a new KML overlay layer
if (cmd.map & & cmd.map.hasOwnProperty("overlay") & & cmd.map.hasOwnProperty("kml") ) {
if (overlays.hasOwnProperty(cmd.map.overlay)) {
map.removeLayer(overlays[cmd.map.overlay]);
existsalready = true;
}
//var opt = {async:true};
2018-09-21 05:26:17 +08:00
overlays[cmd.map.overlay] = omnivore.kml.parse(cmd.map.kml, null, custIco());
2018-01-03 16:31:02 +08:00
if (!existsalready) {
layercontrol.addOverlay(overlays[cmd.map.overlay],cmd.map.overlay);
}
2018-06-07 01:13:50 +08:00
map.addLayer(overlays[cmd.map.overlay]);
2018-06-27 03:42:24 +08:00
if (cmd.map.hasOwnProperty("fit")) { map.fitBounds(overlays[cmd.map.overlay].getBounds()); }
}
// Add a new TOPOJSON overlay layer
if (cmd.map & & cmd.map.hasOwnProperty("overlay") & & cmd.map.hasOwnProperty("topojson") ) {
if (overlays.hasOwnProperty(cmd.map.overlay)) {
map.removeLayer(overlays[cmd.map.overlay]);
existsalready = true;
}
overlays[cmd.map.overlay] = omnivore.topojson.parse(cmd.map.topojson);
if (!existsalready) {
layercontrol.addOverlay(overlays[cmd.map.overlay],cmd.map.overlay);
}
map.addLayer(overlays[cmd.map.overlay]);
if (cmd.map.hasOwnProperty("fit")) { map.fitBounds(overlays[cmd.map.overlay].getBounds()); }
}
// Add a new GPX overlay layer
if (cmd.map & & cmd.map.hasOwnProperty("overlay") & & cmd.map.hasOwnProperty("gpx") ) {
if (overlays.hasOwnProperty(cmd.map.overlay)) {
map.removeLayer(overlays[cmd.map.overlay]);
existsalready = true;
}
2018-09-21 05:26:17 +08:00
overlays[cmd.map.overlay] = omnivore.gpx.parse(cmd.map.gpx, null, custIco());
2018-09-21 03:47:47 +08:00
2018-06-27 03:42:24 +08:00
if (!existsalready) {
layercontrol.addOverlay(overlays[cmd.map.overlay],cmd.map.overlay);
}
map.addLayer(overlays[cmd.map.overlay]);
if (cmd.map.hasOwnProperty("fit")) { map.fitBounds(overlays[cmd.map.overlay].getBounds()); }
2018-01-03 16:31:02 +08:00
}
2018-06-03 23:12:13 +08:00
// Add a new velocity overlay layer
if (cmd.map & & cmd.map.hasOwnProperty("overlay") & & cmd.map.hasOwnProperty("velocity") ) {
if (overlays.hasOwnProperty(cmd.map.overlay)) {
map.removeLayer(overlays[cmd.map.overlay]);
existsalready = true;
}
overlays[cmd.map.overlay] = L.velocityLayer(cmd.map.velocity);
if (!existsalready) {
layercontrol.addOverlay(overlays[cmd.map.overlay],cmd.map.overlay);
}
2018-06-07 01:13:50 +08:00
map.addLayer(overlays[cmd.map.overlay]);
2018-07-01 23:34:23 +08:00
if (cmd.map.hasOwnProperty("fit")) { map.fitBounds(overlays[cmd.map.overlay].getBounds()); }
2018-06-03 23:12:13 +08:00
}
2018-02-01 06:54:03 +08:00
// Add a new overlay layer
2016-06-02 00:19:04 +08:00
if (cmd.map & & cmd.map.hasOwnProperty("overlay") & & cmd.map.hasOwnProperty("url") & & cmd.map.hasOwnProperty("opt")) {
console.log("New overlay:",cmd.map.overlay);
if (overlays.hasOwnProperty(cmd.map.overlay)) { existsalready = true; }
2017-04-20 20:44:19 +08:00
if (cmd.map.hasOwnProperty("wms")) { // special case for wms
2017-05-03 02:46:48 +08:00
if (cmd.map.wms === "grey") {
2018-10-02 17:42:45 +08:00
overlays[cmd.map.overlay] = L.tileLayer.graywms(cmd.map.url, cmd.map.opt);
2017-05-03 02:46:48 +08:00
}
else {
2018-10-02 17:42:45 +08:00
overlays[cmd.map.overlay] = L.tileLayer.wms(cmd.map.url, cmd.map.opt);
2017-05-03 02:46:48 +08:00
}
2017-04-20 20:44:19 +08:00
}
2017-06-19 16:33:27 +08:00
else if (cmd.map.hasOwnProperty("bounds")) { //Image Overlay in the bounds specified (2D Array)
2017-06-26 23:19:05 +08:00
if (cmd.map.bounds.length === 2 & & cmd.map.bounds[0].length === 2 & & cmd.map.bounds[1].length === 2) {
2017-06-28 15:53:42 +08:00
overlays[cmd.map.overlay] = new L.imageOverlay(cmd.map.url, L.latLngBounds(cmd.map.bounds), cmd.map.opt);
2017-06-19 16:33:27 +08:00
}
}
2017-04-20 20:44:19 +08:00
else {
overlays[cmd.map.overlay] = L.tileLayer(cmd.map.url, cmd.map.opt);
}
2017-10-11 06:51:18 +08:00
//if (!existsalready & & !inIframe) {
if (!existsalready) {
2016-06-02 00:19:04 +08:00
layercontrol.addOverlay(overlays[cmd.map.overlay],cmd.map.overlay);
}
2018-06-07 01:13:50 +08:00
map.addLayer(overlays[cmd.map.overlay]);
2016-04-01 18:31:07 +08:00
}
2016-06-02 00:19:04 +08:00
// Swap a base layer
2016-04-01 18:31:07 +08:00
if (cmd.layer & & basemaps.hasOwnProperty(cmd.layer)) {
2016-06-02 00:19:04 +08:00
map.removeLayer(basemaps[baselayername]);
baselayername = cmd.layer;
basemaps[baselayername].addTo(map);
}
2018-06-27 03:42:24 +08:00
// Turn on an existing overlay
if (cmd.hasOwnProperty("showlayer") & & overlays.hasOwnProperty(cmd.showlayer)) {
map.addLayer(overlays[cmd.showlayer]);
}
// Turn off an existing overlay
if (cmd.hasOwnProperty("hidelayer") & & overlays.hasOwnProperty(cmd.hidelayer)) {
map.removeLayer(overlays[cmd.hidelayer]);
2016-04-01 18:31:07 +08:00
}
var clat = map.getCenter().lat;
var clon = map.getCenter().lng;
var czoom = map.getZoom();
if (cmd.hasOwnProperty("lat")) { clat = cmd.lat; }
if (cmd.hasOwnProperty("lon")) { clon = cmd.lon; }
if (cmd.hasOwnProperty("zoom")) { czoom = cmd.zoom; }
2016-06-15 19:57:31 +08:00
if (cmd.hasOwnProperty("cluster")) {
2018-06-07 06:45:06 +08:00
clusterAt = cmd.cluster;
2017-09-06 23:00:37 +08:00
document.getElementById("setclus").value = cmd.cluster;
2018-06-07 06:45:06 +08:00
setCluster(clusterAt);
2016-06-15 19:57:31 +08:00
}
if (cmd.hasOwnProperty("maxage")) {
document.getElementById("maxage").value = cmd.maxage;
setMaxAge();
}
2017-03-04 22:13:05 +08:00
if (cmd.hasOwnProperty("heatmap")) {
heat.setOptions(cmd.heatmap);
heat.redraw();
}
2016-04-01 18:31:07 +08:00
map.setView([clat,clon],czoom);
}
< / script >
< / body >
< / html >