Create the map WKT behavior.

This commit is contained in:
paul121 2020-12-14 09:17:26 -08:00 committed by Michael Stenta
parent 2b13968c4d
commit c7a16d0f5d
3 changed files with 61 additions and 0 deletions

View File

@ -0,0 +1,11 @@
langcode: en
status: true
dependencies:
enforced:
module:
- farm_map
id: wkt
label: WKT
description: 'Displays WKT as a map layer.'
library: 'farm_map/behavior_wkt'
settings: { }

View File

@ -19,3 +19,9 @@ farm_map:
js/farm_map.js: { }
dependencies:
- farm_map/farmOS-map
behavior_wkt:
js:
js/farmOS.map.behaviors.wkt.js: { }
dependencies:
- core/drupalSettings
- farm_map/farm_map

View File

@ -0,0 +1,44 @@
(function () {
farmOS.map.behaviors.wkt = {
attach: function (instance) {
// If WKT was set, create a layer.
if (drupalSettings.farm_map[instance.target].wkt) {
var wkt = drupalSettings.farm_map[instance.target].wkt;
var type = 'vector';
var opts = {
title: 'Geometry',
color: 'orange',
};
if (wkt !== '' && wkt !== 'GEOMETRYCOLLECTION EMPTY') {
type = 'wkt';
opts.wkt = wkt;
}
var layer = instance.addLayer(type, opts);
}
// If edit is true, enable drawing controls.
if (drupalSettings.farm_map[instance.target].behaviors.wkt.edit) {
if (layer !== undefined) {
instance.addBehavior('edit', { layer: layer });
} else {
instance.addBehavior('edit');
var layer = instance.edit.layer;
}
// Add the snappingGrid behavior.
instance.addBehavior('snappingGrid');
}
// Enable the line/polygon measure behavior.
instance.addBehavior('measure', { layer: layer });
// If zoom is true and the layer has features, zoom to them.
// Otherwise, zoom to all vectors.
if (drupalSettings.farm_map[instance.target].behaviors.wkt.zoom && layer !== undefined) {
instance.zoomToLayer(layer);
}
},
weight: 100,
};
}());