1
0
forked from MTSR/mapserver
mapserver/public/js/map/overlays/BorderOverlay.js

96 lines
2.3 KiB
JavaScript
Raw Normal View History

2019-06-11 15:16:41 +03:00
import AbstractGeoJsonOverlay from './AbstractGeoJsonOverlay.js';
2020-04-30 12:31:51 +03:00
import { HtmlSanitizer } from '../../lib/HtmlSanitizer.js';
2019-04-04 09:45:42 +03:00
2019-06-11 15:16:41 +03:00
export default AbstractGeoJsonOverlay.extend({
2019-09-18 12:53:58 +03:00
initialize: function() {
AbstractGeoJsonOverlay.prototype.initialize.call(this, "border");
2019-04-04 09:45:42 +03:00
},
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 + 0.5, entry.z + 0.5]);
2019-04-04 09:45:42 +03:00
});
2019-06-08 15:39:38 +03:00
// closing border
coords.push([
borders[bordername][0].x + 0.5,
borders[bordername][0].z + 0.5
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],
2020-04-30 12:31:51 +03:00
"popupContent": "<b>Border (" + HtmlSanitizer.SanitizeHtml(bordername) + ")</b>"
2019-04-04 09:45:42 +03:00
}
2019-04-04 11:49:55 +03:00
};
2019-04-04 09:45:42 +03:00
//line-points
geoJsonLayer.addData(feature);
});
return geoJsonLayer;
}
});