1
0
forked from MTSR/mapserver

working border

This commit is contained in:
Thomas Rudin 2019-06-08 14:39:38 +02:00
parent 75d4896930
commit c5c7c30c17
2 changed files with 31 additions and 1 deletions

View File

@ -6,16 +6,34 @@ var BorderOverlay = AbstractGeoJsonOverlay.extend({
AbstractGeoJsonOverlay.prototype.initialize.call(this, wsChannel, layerMgr, "border"); AbstractGeoJsonOverlay.prototype.initialize.call(this, wsChannel, layerMgr, "border");
}, },
getMaxDisplayedZoom: function(){
return 1;
},
getMinDisplayedZoom: function(){
return 9;
},
createGeoJson: function(objects){ createGeoJson: function(objects){
var geoJsonLayer = L.geoJSON([], { var geoJsonLayer = L.geoJSON([], {
onEachFeature: function(feature, layer){ onEachFeature: function(feature, layer){
if (feature.properties && feature.properties.popupContent) { if (feature.properties && feature.properties.popupContent) {
layer.bindPopup(feature.properties.popupContent); layer.bindPopup(feature.properties.popupContent);
} }
},
style: function(feature) {
if (feature.properties && feature.properties.color){
return {
color: feature.properties.color,
fill: feature.properties.color,
opacity: 0.3
};
}
} }
}); });
var borders = []; var borders = [];
var borderColors = {}; // { name: color }
objects.forEach(function(obj){ objects.forEach(function(obj){
if (!obj.attributes.name) if (!obj.attributes.name)
@ -25,6 +43,11 @@ var BorderOverlay = AbstractGeoJsonOverlay.extend({
if (!border){ if (!border){
border = []; border = [];
borders[obj.attributes.name] = border; borders[obj.attributes.name] = border;
borderColors[obj.attributes.name] = "#ff7800";
}
if (obj.attributes.color){
borderColors[obj.attributes.name] = obj.attributes.color;
} }
border.push(obj); border.push(obj);
@ -43,6 +66,12 @@ var BorderOverlay = AbstractGeoJsonOverlay.extend({
coords.push([entry.x, entry.z]); coords.push([entry.x, entry.z]);
}); });
// closing border
coords.push([
borders[bordername][0].x,
borders[bordername][0].z
])
var feature = { var feature = {
"type":"Feature", "type":"Feature",
"geometry": { "geometry": {
@ -51,6 +80,7 @@ var BorderOverlay = AbstractGeoJsonOverlay.extend({
}, },
"properties":{ "properties":{
"name": bordername, "name": bordername,
"color": borderColors[bordername],
"popupContent": "<b>Border (" + bordername + ")</b>" "popupContent": "<b>Border (" + bordername + ")</b>"
} }
}; };

View File

@ -44,7 +44,7 @@ var TrainlineOverlay = AbstractGeoJsonOverlay.extend({
line = []; line = [];
lines[obj.attributes.line] = line; lines[obj.attributes.line] = line;
//default or new color //default or new color
lineColors[obj.attributes.line] = obj.attributes.color || "#ff7800"; lineColors[obj.attributes.line] = "#ff7800";
} }
if (obj.attributes.color){ if (obj.attributes.color){