Yaron Koren has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/377330 )
Change subject: Added "leaflet" input type - based on patch by Peter Grassberger
......................................................................
Added "leaflet" input type - based on patch by Peter Grassberger
Change-Id: I2b5422d2d2379a37c1e70e7729d7516a0916d689
---
M PageForms.php
M extension.json
M includes/PF_FormPrinter.php
M libs/PF_maps.js
M libs/PF_maps.offline.js
5 files changed, 101 insertions(+), 6 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/PageForms
refs/changes/30/377330/2
diff --git a/PageForms.php b/PageForms.php
index 3b2a06e..9d12d22 100644
--- a/PageForms.php
+++ b/PageForms.php
@@ -220,6 +220,7 @@
$GLOBALS['wgAutoloadClasses']['PFTokensInput'] = __DIR__ .
'/includes/forminputs/PF_TokensInput.php';
$GLOBALS['wgAutoloadClasses']['PFGoogleMapsInput'] = __DIR__ .
'/includes/forminputs/PF_GoogleMapsInput.php';
$GLOBALS['wgAutoloadClasses']['PFOpenLayersInput'] = __DIR__ .
'/includes/forminputs/PF_OpenLayersInput.php';
+$GLOBALS['wgAutoloadClasses']['PFLeafletInput'] = __DIR__ .
'/includes/forminputs/PF_LeafletInput.php';
$GLOBALS['wgAutoloadClasses']['PFRegExpInput'] = __DIR__ .
'/includes/forminputs/PF_RegExpInput.php';
$GLOBALS['wgAutoloadClasses']['PFRatingInput'] = __DIR__ .
'/includes/forminputs/PF_RatingInput.php';
diff --git a/extension.json b/extension.json
index bb65ea4..3f2355d 100644
--- a/extension.json
+++ b/extension.json
@@ -138,6 +138,7 @@
"PFTokensInput": "includes/forminputs/PF_TokensInput.php",
"PFGoogleMapsInput":
"includes/forminputs/PF_GoogleMapsInput.php",
"PFOpenLayersInput":
"includes/forminputs/PF_OpenLayersInput.php",
+ "PFLeafletInput": "includes/forminputs/PF_LeafletInput.php",
"PFRegExpInput": "includes/forminputs/PF_RegExpInput.php",
"PFRatingInput": "includes/forminputs/PF_RatingInput.php",
"PFWikiPage": "includes/wikipage/PF_WikiPage.php",
diff --git a/includes/PF_FormPrinter.php b/includes/PF_FormPrinter.php
index 7b4db18..3319d3e 100644
--- a/includes/PF_FormPrinter.php
+++ b/includes/PF_FormPrinter.php
@@ -65,6 +65,7 @@
$this->registerInputType( 'PFGoogleMapsInput' );
}
$this->registerInputType( 'PFOpenLayersInput' );
+ $this->registerInputType( 'PFLeafletInput' );
}
// All-purpose setup hook.
diff --git a/libs/PF_maps.js b/libs/PF_maps.js
index f5c2508..37814f3 100644
--- a/libs/PF_maps.js
+++ b/libs/PF_maps.js
@@ -25,6 +25,22 @@
google.maps.event.addListener( map, 'dblclick', function( event
) {
clearTimeout( update_timeout );
});
+ } else if (mapService == "Leaflet") {
+ var mapCanvas = inputDiv.find('.pfMapCanvas').get(0);
+ var mapOptions = {
+ zoom: 1,
+ center: [0, 0]
+ };
+ var layerOptions = {
+ attribution: '© <a
href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
+ };
+
+ var map = L.map(mapCanvas, mapOptions);
+ new
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
layerOptions).addTo(map);
+
+ map.on( 'click', function( event ) {
+ leafletSetMarker( event.latlng );
+ });
} else { // if ( mapService == "OpenLayers" ) {
var mapCanvasID = inputDiv.find('.pfMapCanvas').attr('id');
var map = new OpenLayers.Map( mapCanvasID );
@@ -93,7 +109,7 @@
if ( coordsInput.val() != '' ) {
setMarkerFromCoordinates();
- map.setZoom(14);
+ map.setZoom( 14 );
}
function setMarkerFromAddress() {
@@ -118,9 +134,9 @@
alert("Geocode was not successful for
the following reason: " + status);
}
});
- } else { // if ( mapService == "OpenLayers" ) {
+ } else { // Leaflet, OpenLayers
// Do nothing, for now - address lookup/geocode is
- // not yet enabled for OpenLayers.
+ // not yet enabled for Leaflet or OpenLayers.
}
}
@@ -145,6 +161,10 @@
var gmPoint = new google.maps.LatLng( lat, lon );
googleMapsSetMarker( gmPoint );
map.setCenter( gmPoint );
+ } else if ( mapService == "Leaflet" ){
+ var lPoint = L.latLng( lat, lon );
+ leafletSetMarker( lPoint );
+ map.setView( lPoint );
} else { // if ( mapService == "OpenLayers" ) {
var olPoint = toOpenLayersLonLat( map, lat, lon );
openLayersSetMarker( olPoint );
@@ -188,6 +208,29 @@
.parent().find('.pfCoordsInputHelpers').remove();
}
+ function leafletSetMarker( location ) {
+ if ( marker == null) {
+ marker = L.marker( location ).addTo( map );
+ } else {
+ marker.setLatLng( location, { draggable: true } );
+ }
+ marker.dragging.enable();
+
+ function setInput() {
+ var stringVal = pfRoundOffDecimal(
marker.getLatLng().lat ) + ', ' +
+ pfRoundOffDecimal( marker.getLatLng().lng );
+ coordsInput.val( stringVal )
+ .attr( 'data-original-value', stringVal )
+ .removeClass( 'modifiedInput' )
+
.parent().find('.pfCoordsInputHelpers').remove();
+ }
+
+ marker.off('dragend').on('dragend', function( event ) {
+ setInput();
+ });
+ setInput();
+ }
+
function openLayersSetMarker( location ) {
// OpenLayers does not have a real marker move
// option - instead, just delete the old marker
@@ -214,6 +257,9 @@
jQuery(".pfGoogleMapsInput").each( function() {
setupMapFormInput( jQuery(this), "Google Maps" );
});
+ jQuery(".pfLeafletInput").each( function() {
+ setupMapFormInput( jQuery(this), "Leaflet" );
+ });
jQuery(".pfOpenLayersInput").each( function() {
setupMapFormInput( jQuery(this), "OpenLayers" );
});
diff --git a/libs/PF_maps.offline.js b/libs/PF_maps.offline.js
index 7b4950e..a3ab614 100644
--- a/libs/PF_maps.offline.js
+++ b/libs/PF_maps.offline.js
@@ -42,6 +42,29 @@
}
+ function leafletSetMarker( location ) {
+ if ( marker == null) {
+ marker = L.marker( location ).addTo( map );
+ } else {
+ marker.setLatLng( location, { draggable: true } );
+ }
+ marker.dragging.enable();
+
+ function setInput() {
+ var stringVal = pfRoundOffDecimal(
marker.getLatLng().lat ) + ', ' +
+ pfRoundOffDecimal( marker.getLatLng().lng );
+ coordsInput.val( stringVal )
+ .attr( 'data-original-value', stringVal )
+ .removeClass( 'modifiedInput' )
+
.parent().find('.pfCoordsInputHelpers').remove();
+ }
+
+ marker.off('dragend').on('dragend', function( event ) {
+ setInput();
+ });
+ setInput();
+ }
+
function openLayersSetMarker( location ) {
// OpenLayers does not have a real marker move
// option - instead, just delete the old marker
@@ -83,6 +106,22 @@
});
google.maps.event.addListener( map, 'dblclick', function( event
) {
clearTimeout( update_timeout );
+ });
+ } else if (mapService == "Leaflet") {
+ var mapCanvas = inputDiv.find('.pfMapCanvas').get(0);
+ var mapOptions = {
+ zoom: 1,
+ center: [0, 0]
+ };
+ var layerOptions = {
+ attribution: '© <a
href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
+ };
+
+ var map = L.map(mapCanvas, mapOptions);
+ new
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
layerOptions).addTo(map);
+
+ map.on( 'click', function( event ) {
+ leafletSetMarker( event.latlng );
});
} else { // if ( mapService == "OpenLayers" ) {
var mapCanvasID = inputDiv.find( '.pfMapCanvas' ).attr( 'id' );
@@ -127,6 +166,10 @@
var gmPoint = new google.maps.LatLng( lat, lon );
googleMapsSetMarker( gmPoint );
map.setCenter( gmPoint );
+ } else if ( mapService == "Leaflet" ){
+ var lPoint = L.latLng( lat, lon );
+ leafletSetMarker( lPoint );
+ map.setView( lPoint );
} else { // if ( mapService == "OpenLayers" ) {
var olPoint = toOpenLayersLonLat( map, lat, lon );
openLayersSetMarker( olPoint );
@@ -183,10 +226,10 @@
alert("Geocode was not successful for
the following reason: " + status);
}
});
- } // else { if ( mapService == "OpenLayers" ) {
+ } else { // Leaflet, OpenLayers
// Do nothing, for now - address lookup/geocode is
- // not yet enabled for OpenLayers.
- // }
+ // not yet enabled for Leaflet or OpenLayers.
+ }
}
inputDiv.find('.pfAddressInput').keypress( function( e ) {
@@ -214,6 +257,9 @@
jQuery(".pfGoogleMapsInput").each( function() {
setupMapFormInput( jQuery(this), "Google Maps" );
});
+ jQuery(".pfLeafletInput").each( function() {
+ setupMapFormInput( jQuery(this), "Leaflet" );
+ });
jQuery(".pfOpenLayersInput").each( function() {
setupMapFormInput( jQuery(this), "OpenLayers" );
});
--
To view, visit https://gerrit.wikimedia.org/r/377330
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I2b5422d2d2379a37c1e70e7729d7516a0916d689
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/PageForms
Gerrit-Branch: master
Gerrit-Owner: Yaron Koren <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits