Skip to content

Commit

Permalink
Show inverted polygon for allowed zone
Browse files Browse the repository at this point in the history
  • Loading branch information
nrenner authored and bagage committed Dec 4, 2020
1 parent 04d549a commit 1d78e03
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
3 changes: 3 additions & 0 deletions css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,9 @@ input#trackname:focus:invalid {
.circlego-draw-enabled {
cursor: pointer;
}
.circlego-outside {
cursor: not-allowed;
}

#map {
/* center error message horizontally */
Expand Down
43 changes: 41 additions & 2 deletions js/plugin/CircleGoArea.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
BR.CircleGoArea = L.Control.extend({
circleLayer: null,
outsideAreaRenderer: L.svg({ padding: 1 }),

options: {
radius: 1000, // in meters
Expand Down Expand Up @@ -87,12 +88,45 @@ BR.CircleGoArea = L.Control.extend({
setNogoCircle: function(center) {
if (center) {
var polygon = this.circleToPolygon(center, this.options.radius);
$('#nogoJSON').val(JSON.stringify(polygon));
var geoJson = JSON.stringify(polygon);
$('#nogoJSON').val(geoJson);
$('#nogoBuffer').val(0);
this.nogos.uploadNogos();

var polygonClone = JSON.parse(geoJson);
this.setOutsideArea(polygonClone);
} else {
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) {
Expand All @@ -119,7 +153,12 @@ BR.CircleGoArea = L.Control.extend({

this.clear();
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);
},

Expand Down

0 comments on commit 1d78e03

Please sign in to comment.