Remove the current location layer if an asset has no location.

This commit is contained in:
paul121 2020-07-02 09:57:43 -07:00 committed by Michael Stenta
parent 19db0bd560
commit 01c7147ddb
2 changed files with 15 additions and 11 deletions

View File

@ -3,7 +3,7 @@
// wkt from the hidden input field and preview it on the map. // wkt from the hidden input field and preview it on the map.
Drupal.ajax.prototype.commands.previewCurrentLocation = function() { Drupal.ajax.prototype.commands.previewCurrentLocation = function() {
var wkt = $('#current-location input[name="move[current_location]"]').val(); var wkt = $('#current-location input[name="move[current_location]"]').val();
if (wkt) { if (wkt !== 'undefined') {
farmOS.map.behaviors.move.previewCurrentLocation(wkt); farmOS.map.behaviors.move.previewCurrentLocation(wkt);
} }
} }

View File

@ -32,16 +32,20 @@
this.currentLocationLayer = null; this.currentLocationLayer = null;
} }
// Create current location layer with the WKT. // Only add a layer if WKT is not an empty string.
// Do not put the layer inside a group, because map.removeLayer() (used if (wkt.length > 0) {
// above) does not recurse into layer groups.
var opts = { // Create current location layer with the WKT.
title: 'Current Location', // Do not put the layer inside a group, because map.removeLayer() (used
color: 'blue', // above) does not recurse into layer groups.
wkt: wkt, var opts = {
}; title: 'Current Location',
this.currentLocationLayer = this.instance.addLayer('wkt', opts); color: 'blue',
this.instance.zoomToVectors(); wkt: wkt,
};
this.currentLocationLayer = this.instance.addLayer('wkt', opts);
this.instance.zoomToVectors();
}
}, },
// Recreate the Movement map layer. // Recreate the Movement map layer.