1
0
forked from MTSR/mapserver
mapserver/static/js/overlays/BorderOverlay.js

96 lines
2.3 KiB
JavaScript
Raw Normal View History

2019-04-04 11:49:55 +03:00
/* exported BorderOverlay */
/* globals AbstractGeoJsonOverlay: true */
2019-04-04 09:45:42 +03:00
var BorderOverlay = AbstractGeoJsonOverlay.extend({
initialize: function(wsChannel, layerMgr) {
AbstractGeoJsonOverlay.prototype.initialize.call(this, wsChannel, layerMgr, "border");
},
2019-06-08 15:39:38 +03:00
getMaxDisplayedZoom: function(){
return 1;
},
getMinDisplayedZoom: function(){
return 9;
},
2019-04-04 09:45:42 +03:00
createGeoJson: function(objects){
var geoJsonLayer = L.geoJSON([], {
onEachFeature: function(feature, layer){
if (feature.properties && feature.properties.popupContent) {
layer.bindPopup(feature.properties.popupContent);
}
2019-06-08 15:39:38 +03:00
},
style: function(feature) {
if (feature.properties && feature.properties.color){
return {
color: feature.properties.color,
fill: feature.properties.color,
opacity: 0.3
};
}
2019-04-04 09:45:42 +03:00
}
});
var borders = [];
2019-06-08 15:39:38 +03:00
var borderColors = {}; // { name: color }
2019-04-04 09:45:42 +03:00
objects.forEach(function(obj){
if (!obj.attributes.name)
2019-04-04 11:49:55 +03:00
return;
2019-04-04 09:45:42 +03:00
var border = borders[obj.attributes.name];
if (!border){
border = [];
borders[obj.attributes.name] = border;
2019-06-08 15:39:38 +03:00
borderColors[obj.attributes.name] = "#ff7800";
}
if (obj.attributes.color){
borderColors[obj.attributes.name] = obj.attributes.color;
2019-04-04 09:45:42 +03:00
}
border.push(obj);
});
//Order by index and display
Object.keys(borders).forEach(function(bordername){
borders[bordername].sort(function(a,b){
return parseInt(a.attributes.index) - parseInt(b.attributes.index);
});
var coords = [];
//Add stations
borders[bordername].forEach(function(entry){
coords.push([entry.x, entry.z]);
});
2019-06-08 15:39:38 +03:00
// closing border
coords.push([
borders[bordername][0].x,
borders[bordername][0].z
2019-06-09 19:32:36 +03:00
]);
2019-06-08 15:39:38 +03:00
2019-04-04 09:45:42 +03:00
var feature = {
"type":"Feature",
"geometry": {
"type":"LineString",
"coordinates":coords
},
"properties":{
2019-04-04 11:49:55 +03:00
"name": bordername,
2019-06-08 15:39:38 +03:00
"color": borderColors[bordername],
2019-04-04 09:45:42 +03:00
"popupContent": "<b>Border (" + bordername + ")</b>"
}
2019-04-04 11:49:55 +03:00
};
2019-04-04 09:45:42 +03:00
//line-points
geoJsonLayer.addData(feature);
});
return geoJsonLayer;
}
});