Skip to content

Commit

Permalink
Issue #6: Add draw compatibility for recent Leaflet version
Browse files Browse the repository at this point in the history
  • Loading branch information
indigoxela committed Oct 10, 2022
1 parent a2a3507 commit 0e7b8fa
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
25 changes: 25 additions & 0 deletions js/leaflet-draw-compat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* @file
* Override methods from Leaflet.draw for compatibility with Leaflet 1.9+.
*
* Prevent deprecation warnings:
* "Deprecated use of _flat, please use L.LineUtil.isFlat instead."
* Deprecated since 2017, (will be) removed in 2.x.
*/
L.Edit.Poly.include({
_defaultShape: function () {
if (!L.LineUtil.isFlat) {
return this._latlngs;
}
return L.LineUtil.isFlat(this._poly._latlngs) ? this._poly._latlngs : this._poly._latlngs[0];
}
});

L.Edit.PolyVerticesEdit.include({
_defaultShape: function () {
if (!L.LineUtil.isFlat) {
return this._poly._latlngs;
}
return L.LineUtil.isFlat(this._latlngs) ? this._latlngs : this._latlngs[0];
}
});
10 changes: 7 additions & 3 deletions leaflet_widget.module
Original file line number Diff line number Diff line change
Expand Up @@ -307,20 +307,24 @@ function leaflet_widget_process_geojson($geojson) {
* Implements hook_library_info().
*/
function leaflet_widget_library_info() {
$libraries_path = backdrop_get_path('module', 'leaflet_widget') . '/libraries';
$path = backdrop_get_path('module', 'leaflet_widget');

$libraries['Leaflet.draw'] = array(
'title' => t('Leaflet Draw Library'),
'version' => '0.4.14',
'website' => 'https://github.com/Leaflet/Leaflet.draw',
'js' => array(
$libraries_path . '/Leaflet.draw/dist/leaflet.draw-src.js' => array(
$path . '/libraries/Leaflet.draw/dist/leaflet.draw.js' => array(
'type' => 'file',
'group' => JS_LIBRARY,
),
$path . '/js/leaflet-draw-compat.js' => array(
'type' => 'file',
'group' => JS_LIBRARY,
),
),
'css' => array(
$libraries_path . '/Leaflet.draw/dist/leaflet.draw.css' => array(
$path . '/libraries/Leaflet.draw/dist/leaflet.draw.css' => array(
'type' => 'file',
'media' => 'all',
),
Expand Down

0 comments on commit 0e7b8fa

Please sign in to comment.