diff --git a/plugins/tiddlywiki/geospatial/docs/geolayer.tid b/plugins/tiddlywiki/geospatial/docs/geolayer.tid index 5253fce00..5a1bf7ab5 100644 --- a/plugins/tiddlywiki/geospatial/docs/geolayer.tid +++ b/plugins/tiddlywiki/geospatial/docs/geolayer.tid @@ -15,6 +15,8 @@ The following attributes are supported: |''lat'' |Optional latitude of marker if json attribute missing | |''long'' |Optional longitude of marker if json attribute missing | |''alt'' |Optional altitude of marker if json attribute missing | +|''draggable'' |Set to "yes" to make the marker draggable | +|''updateActions'' |Optional actions when the marker is dragged other otherwise modified. The variables ''lat'' and ''long'' contain the new coordinates of the marker | Note that the `<$geolayer>` widget can be used in one of two modes: diff --git a/plugins/tiddlywiki/geospatial/docs/geomap.tid b/plugins/tiddlywiki/geospatial/docs/geomap.tid index 0cc31ecbd..20c0d426e 100644 --- a/plugins/tiddlywiki/geospatial/docs/geomap.tid +++ b/plugins/tiddlywiki/geospatial/docs/geomap.tid @@ -115,3 +115,8 @@ If no base layers are defined by `<$geobaselayer>` widgets within the `<$geomap> <$data $compound-tiddler="$:/plugins/tiddlywiki/geospatial/tests/widgets/geomap-refresh"/> <$data $tiddler="$:/plugins/tiddlywiki/geospatial"/> + +<$testcase> +<$data $compound-tiddler="$:/plugins/tiddlywiki/geospatial/tests/widgets/geomap-draggable-marker"/> +<$data $tiddler="$:/plugins/tiddlywiki/geospatial"/> + diff --git a/plugins/tiddlywiki/geospatial/tests/widgets/geomap-draggable-marker.tid b/plugins/tiddlywiki/geospatial/tests/widgets/geomap-draggable-marker.tid new file mode 100644 index 000000000..b0583a6ff --- /dev/null +++ b/plugins/tiddlywiki/geospatial/tests/widgets/geomap-draggable-marker.tid @@ -0,0 +1,40 @@ +title: $:/plugins/tiddlywiki/geospatial/tests/widgets/geomap-draggable-marker +description: geomap widget with draggable marker +type: text/vnd.tiddlywiki-multiple +tags: [[$:/tags/wiki-test-spec]] + +title: Description +text: Map with draggable marker ++ +title: Oxford +lat: 51.751944 +long: -1.257778 +alt: 0 ++ +title: Output + +\procedure update-actions() +<$action-log/> +<$action-setfield $tiddler="Oxford" $field="lat" $value=<>/> +<$action-setfield $tiddler="Oxford" $field="long" $value=<>/> +\end + +<$geomap + state=<> +> + <$tiddler tiddler="Oxford"> + <$geolayer + lat={{!!lat}} + long={{!!long}} + alt={{!!alt}} + color={{!!color}} + name={{!!title}} + draggable="yes" + updateActions=<> + /> + + ++ +title: ExpectedResult + +

\ No newline at end of file diff --git a/plugins/tiddlywiki/geospatial/widgets/geomap.js b/plugins/tiddlywiki/geospatial/widgets/geomap.js index 63a2ce97a..8695fd335 100644 --- a/plugins/tiddlywiki/geospatial/widgets/geomap.js +++ b/plugins/tiddlywiki/geospatial/widgets/geomap.js @@ -185,14 +185,23 @@ GeomapWidget.prototype.refreshMap = function() { ] }; } - var layer = $tw.Leaflet.geoJSON(geoJson,{ + var draggable = widget.getAttribute("draggable","no") === "yes", + layer = $tw.Leaflet.geoJSON(geoJson,{ style: function(geoJsonFeature) { return { color: widget.getAttribute("color","yellow") } }, pointToLayer: function(geoJsonPoint,latlng) { - $tw.Leaflet.marker(latlng,{icon: myIcon,draggable: false}).addTo(markers); + var marker = $tw.Leaflet.marker(latlng,{icon: myIcon,draggable: draggable}); + marker.addTo(markers); + marker.on("moveend",function(event) { + var latlng = event.sourceTarget.getLatLng(); + self.invokeActionString(widget.getAttribute("updateActions"),null,event,{ + lat: latlng.lat, + long: latlng.lng + }); + }); return markers; }, onEachFeature: function(feature,layer) {