Show inverted polygon for allowed zone
This commit is contained in:
parent
04d549ad61
commit
1d78e03d0a
2 changed files with 44 additions and 2 deletions
|
|
@ -200,6 +200,9 @@ input#trackname:focus:invalid {
|
||||||
.circlego-draw-enabled {
|
.circlego-draw-enabled {
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
.circlego-outside {
|
||||||
|
cursor: not-allowed;
|
||||||
|
}
|
||||||
|
|
||||||
#map {
|
#map {
|
||||||
/* center error message horizontally */
|
/* center error message horizontally */
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
BR.CircleGoArea = L.Control.extend({
|
BR.CircleGoArea = L.Control.extend({
|
||||||
circleLayer: null,
|
circleLayer: null,
|
||||||
|
outsideAreaRenderer: L.svg({ padding: 1 }),
|
||||||
|
|
||||||
options: {
|
options: {
|
||||||
radius: 1000, // in meters
|
radius: 1000, // in meters
|
||||||
|
|
@ -87,14 +88,47 @@ BR.CircleGoArea = L.Control.extend({
|
||||||
setNogoCircle: function(center) {
|
setNogoCircle: function(center) {
|
||||||
if (center) {
|
if (center) {
|
||||||
var polygon = this.circleToPolygon(center, this.options.radius);
|
var polygon = this.circleToPolygon(center, this.options.radius);
|
||||||
$('#nogoJSON').val(JSON.stringify(polygon));
|
var geoJson = JSON.stringify(polygon);
|
||||||
|
$('#nogoJSON').val(geoJson);
|
||||||
$('#nogoBuffer').val(0);
|
$('#nogoBuffer').val(0);
|
||||||
this.nogos.uploadNogos();
|
this.nogos.uploadNogos();
|
||||||
|
|
||||||
|
var polygonClone = JSON.parse(geoJson);
|
||||||
|
this.setOutsideArea(polygonClone);
|
||||||
} else {
|
} else {
|
||||||
this.nogos.clear();
|
this.nogos.clear();
|
||||||
|
this.map.removeLayer(this.outsideArea);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
setOutsideArea: function(polygon) {
|
||||||
|
var inner = polygon.features[0].geometry.coordinates.concat(polygon.features[1].geometry.coordinates);
|
||||||
|
var world = [[180, 90], [-180, 90], [-180, -90], [180, -90], [180, 90]];
|
||||||
|
polygon.features[0].geometry.coordinates = [world, inner];
|
||||||
|
polygon.features[0].geometry.type = 'Polygon';
|
||||||
|
polygon.features.pop();
|
||||||
|
|
||||||
|
if (this.outsideArea) {
|
||||||
|
this.map.removeLayer(this.outsideArea);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.outsideArea = L.geoJson(polygon, {
|
||||||
|
renderer: this.outsideAreaRenderer,
|
||||||
|
style: function(feature) {
|
||||||
|
return {
|
||||||
|
weight: 2,
|
||||||
|
color: 'black',
|
||||||
|
opacity: 0.4,
|
||||||
|
fillColor: 'black',
|
||||||
|
fillOpacity: 0.4,
|
||||||
|
className: 'circlego-outside'
|
||||||
|
};
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.on('click', L.DomEvent.stop)
|
||||||
|
.addTo(this.map);
|
||||||
|
},
|
||||||
|
|
||||||
onMapClick: function(e) {
|
onMapClick: function(e) {
|
||||||
this.setCircle([e.latlng.lng, e.latlng.lat], false);
|
this.setCircle([e.latlng.lng, e.latlng.lat], false);
|
||||||
},
|
},
|
||||||
|
|
@ -119,7 +153,12 @@ BR.CircleGoArea = L.Control.extend({
|
||||||
|
|
||||||
this.clear();
|
this.clear();
|
||||||
marker.addTo(this.circleLayer);
|
marker.addTo(this.circleLayer);
|
||||||
if (!skipNogo) this.setNogoCircle(center);
|
if (!skipNogo) {
|
||||||
|
this.setNogoCircle(center);
|
||||||
|
} else {
|
||||||
|
var polygon = this.circleToPolygon(center, this.options.radius);
|
||||||
|
this.setOutsideArea(polygon);
|
||||||
|
}
|
||||||
this.draw(false);
|
this.draw(false);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue