Inchikutty has uploaded a new change for review.
https://gerrit.wikimedia.org/r/141122
Change subject: [WIP] Adds OSM parameter to coordinate template
......................................................................
[WIP] Adds OSM parameter to coordinate template
Adds OSM parameter to coordinate template if coordinate is seleceted via
OSM based map.
Change-Id: I3535202c92a7a0a849dd32ad0253e6885a23505a
---
M resources/mw.GeoMap.js
M resources/mw.UploadWizardDetails.js
2 files changed, 107 insertions(+), 168 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/UploadWizard
refs/changes/22/141122/1
diff --git a/resources/mw.GeoMap.js b/resources/mw.GeoMap.js
index 1176468..f34a7b8 100644
--- a/resources/mw.GeoMap.js
+++ b/resources/mw.GeoMap.js
@@ -12,50 +12,50 @@
( function ( mw, $ ) {
mw.GeoMap = function ( $form ) {
- var _this = this;
- _this.$form = $form;
- _this.isGeoMapInitialized = false;
- _this.map = null;
- _this.address = '';
- _this.zoom = 6;
+ var geo = this;
+ geo.$form = $form;
+ geo.isGeoMapInitialized = false;
+ geo.map = null;
+ geo.address = '';
+ geo.zoom = 8;
mw.GeoMap.mapId = ( mw.GeoMap.mapId || 0 ) + 1;
- _this.mapDiv = $( '<div>' ).addClass( 'mwe-loc-map' ).attr( 'id',
'mwe-location-map' + mw.GeoMap.mapId );
+ geo.mapDiv = $( '<div>' ).addClass( 'mwe-loc-map' ).attr( 'id',
'mwe-location-map' + mw.GeoMap.mapId );
- _this.geoLocation = $( '<div>' ).attr( 'id', 'mwe-loc-map-label' +
mw.GeoMap.mapId )
+ geo.geoLocation = $( '<div>' ).attr( 'id', 'mwe-loc-map-label' +
mw.GeoMap.mapId )
.append( $( '<div>' ).addClass( 'mwe-loc-map-label' ).attr(
'id', 'simpleSearch' )
.append( $( '<input>' ).attr( { type: 'text', size: 41,
id: 'searchInput', placeholder: 'Search a place' } ),
$( '<input>' ).addClass( 'searchButton' ).attr(
{ type: 'button', id: 'searchButton' } ) ) );
- var geoMapDiv = $( '<div>' ).addClass( 'mwe-location-map' ).append(
_this.geoLocation, _this.mapDiv );
- _this.$form.find( '.mwe-location-label' ).append( geoMapDiv );
+ var geoMapDiv = $( '<div>' ).addClass( 'mwe-location-map' ).append(
geo.geoLocation, geo.mapDiv );
+ geo.$form.find( '.mwe-location-label' ).append( geoMapDiv );
- var $list = _this.$form.find( '.mwe-loc-lat, .mwe-loc-lon' );
+ var $list = geo.$form.find( '.mwe-loc-lat, .mwe-loc-lon' );
$list.on( 'input keyup change cut paste uw-copy', $.debounce( 250,
function () {
if ( $list.valid() && !( $list.is( ':blank' ) ) ) {
- if ( _this.isGeoMapInitialized ) {
- _this.geoMapInit( $list.eq( 0 ).val(),
$list.eq( 1 ).val() );
+ if ( geo.isGeoMapInitialized ) {
+ geo.geoMapInit( $list.eq( 0 ).val(), $list.eq(
1 ).val() );
}
else {
- _this.staticMap( $list.eq( 0 ).val(), $list.eq(
1 ).val() );
+ geo.staticMap( $list.eq( 0 ).val(), $list.eq( 1
).val() );
}
- _this.reverseGeocoding( $list.eq( 0 ).val(), $list.eq(
1 ).val() );
+ geo.reverseGeocoding( $list.eq( 0 ).val(), $list.eq( 1
).val() );
}
else {
- _this.mapRemove();
- _this.geoLocation.find( '#searchInput' ).val( '' );
+ geo.mapRemove();
+ geo.geoLocation.find( '#searchInput' ).val( '' );
} } )
);
- _this.geoLocation.find( '#searchInput' ).on( 'keypress', function ( e )
{
+ geo.geoLocation.find( '#searchInput' ).on( 'keypress', function ( e ) {
if ( e.which === 13 ) {
- _this.geocoding( _this.geoLocation.find( '#searchInput'
).val() );
+ geo.geocoding( geo.geoLocation.find( '#searchInput'
).val() );
}
} );
- _this.geoLocation.find( '#searchButton' ).click( function () {
- _this.geocoding( _this.geoLocation.find( '#searchInput' ).val()
);
+ geo.geoLocation.find( '#searchButton' ).click( function () {
+ geo.geocoding( geo.geoLocation.find( '#searchInput' ).val() );
} );
- _this.marker = L.marker( [ 0, 0 ] );
+ geo.marker = L.marker( [ 0, 0 ] );
L.Icon.Default.imagePath = mw.config.get( 'wgScriptPath' ) +
'/extensions/UploadWizard/resources/leaflet/images';
};
@@ -80,20 +80,20 @@
*@param {Number} longitude
*/
staticMap: function ( latVal, lonVal ) {
- var _this = this;
- _this.mapRemove();
- _this.mapDiv.addClass( 'mwe-upwiz-status-progress' );
- var link = _this.staticMapLink( latVal, lonVal );
- $( '<img>' ).attr( 'src', link ).addClass( 'mwe-loc-map'
).appendTo( _this.mapDiv )
+ var geo = this;
+ geo.mapRemove();
+ geo.mapDiv.addClass( 'mwe-upwiz-status-progress' );
+ var link = geo.staticMapLink( latVal, lonVal );
+ $( '<img>' ).attr( 'src', link ).addClass( 'mwe-loc-map'
).appendTo( geo.mapDiv )
.click( function () {
- _this.mapRemove();
- _this.geoMapInit( latVal, lonVal );
+ geo.mapRemove();
+ geo.geoMapInit( latVal, lonVal );
} );
- $( '<div>' ).addClass( 'mwe-loc-link' ).text( 'Click on image
to open leaflet map' ).appendTo( _this.mapDiv ).hide();
- _this.mapDiv.on( 'mouseenter', function () {
+ $( '<div>' ).addClass( 'mwe-loc-link' ).text( 'Click on image
to open leaflet map' ).appendTo( geo.mapDiv ).hide();
+ geo.mapDiv.on( 'mouseenter', function () {
$( this ).find( '.mwe-loc-link' ).show();
} );
- _this.mapDiv.on( 'mouseleave', function () {
+ geo.mapDiv.on( 'mouseleave', function () {
$( this ).find( '.mwe-loc-link' ).hide();
} );
},
@@ -104,24 +104,24 @@
*@param {Number} longitude
*/
geoMapInit: function ( latVal, lonVal ) {
- var _this = this,
+ var geo = this,
latlng = L.latLng ( latVal, lonVal );
- if ( !_this.isGeoMapInitialized ) {
- _this.map = new L.map( _this.mapDiv.attr('id'), {
center: [ latVal, lonVal ], zoom: _this.zoom, dragging: false } );
- _this.map.on( 'click', function ( e ) {
- _this.mapViewToinputs( e.latlng );
+ if ( !geo.isGeoMapInitialized ) {
+ geo.map = new L.map( geo.mapDiv.attr( 'id' ), { center:
[ latVal, lonVal ], zoom: geo.zoom, dragging: true } );
+ geo.map.on( 'click', function ( e ) {
+ geo.mapViewToinputs( e.latlng );
} );
- _this.isGeoMapInitialized = true;
+ geo.isGeoMapInitialized = true;
new L.TileLayer(
'http://{s}.mqcdn.com/tiles/1.0.0/osm/{z}/{x}/{y}.png', {
minZoom: 1,
- maxZoom: 16,
+ maxZoom: 25,
attribution: 'Data, imagery and map information
provided by' +
'<a href=' +
'http://open.mapquest.co.uk' + ' target=_blank>MapQuest</a>' + ',' +
'<a href=' +
'http://www.openstreetmap.org/' + ' target=_blank>OpenStreetMap</a> and
contributors',
subdomains:
['otile1','otile2','otile3','otile4'] } )
- .addTo( _this.map );
+ .addTo( geo.map );
}
- _this.markMapView( latlng );
+ geo.markMapView( latlng );
},
/**
@@ -160,10 +160,10 @@
*@param {L.latLng} latlng
*/
markMapView: function ( latlng ) {
- var _this = this;
- _this.map.setView ( latlng, _this.zoom );
- _this.marker.setLatLng( latlng );
- _this.marker.addTo( _this.map );
+ var geo = this;
+ geo.map.setView ( latlng, geo.zoom );
+ geo.marker.setLatLng( latlng );
+ geo.marker.addTo( geo.map );
},
/**
@@ -204,24 +204,24 @@
*@param {String} location
*/
geocoding: function ( location ) {
- var _this = this,
- url = _this.geocodingUrl( location );
+ var geo = this,
+ url = geo.geocodingUrl( location );
$.getJSON( url, function ( data ) {
if ( data.length ) {
var latlng = L.latLng ( data[0].lat,
data[0].lon ),
- $list = _this.$form.find(
'.mwe-loc-lat, .mwe-loc-lon' );
+ $list = geo.$form.find( '.mwe-loc-lat,
.mwe-loc-lon' );
$list.eq( 0 ).val( latlng.lat.toFixed( 4 ) );
$list.eq( 1 ).val( latlng.lng.toFixed( 4 ) );
- _this.locationResults( data[0] );
- if ( !( _this.isGeoMapInitialized ) ) {
- _this.staticMap( latlng.lat.toFixed( 4
), latlng.lng.toFixed( 4 ) );
+ geo.locationResults( data[0] );
+ if ( !( geo.isGeoMapInitialized ) ) {
+ geo.staticMap( latlng.lat.toFixed( 4 ),
latlng.lng.toFixed( 4 ) );
}
else {
- _this.markMapView( latlng );
+ geo.markMapView( latlng );
}
}
else {
- _this.geoLocation.find( '#searchInput' ).val(
'' ).attr( 'placeholder', 'Incorrect search query, Search again!!' );
+ geo.geoLocation.find( '#searchInput' ).val( ''
).attr( 'placeholder', 'Incorrect search query, Search again!!' );
}
} );
},
@@ -232,12 +232,12 @@
*@param {Number} longitude
*/
reverseGeocoding: function ( latVal, lonVal ) {
- var _this = this,
- url = _this.reverseGeocodingUrl( latVal, lonVal ),
+ var geo = this,
+ url = geo.reverseGeocodingUrl( latVal, lonVal ),
address;
$.getJSON( url, function ( data ) {
if ( !data.error ) {
- _this.locationResults( data );
+ geo.locationResults( data );
}
} );
},
@@ -248,19 +248,17 @@
*/
locationResults: function ( data ) {
if ( JSON.stringify( data ).length > 0 ) {
- var _this = this,
+ var geo = this,
address = '',
- zoom = _this.zoom;
+ zoom = geo.zoom;
$.each( data.address, function ( i, value ) {
// generating display address from
geocoded/reverse geocoded result-json object.
if ( !( ( i === 'country' ) || ( i ===
'country_code' )|| ( i === 'postcode' ) ||
( i === 'state_district' ) || ( i ===
'county' ) ) && value
) {
- if ( _this.geoLocation.find(
'#searchInput' ).val() !== value ) {
- address += value + ',';
- value = false;
- }
+ address += value + ',';
+ value = false;
}
else if ( ( i === 'country' ) && value ) {
address += value;
@@ -270,106 +268,58 @@
value = false;
}
- //Setting zoom level according to 'importance'
element; nominatim describes 'importance'as
- //Indicator of how important a place is. Values
in the range 0 to 1 where 1 is most important.
- //The major weight of importance comes indeed
from the Wikipedia link count.
- //Incase of a detailed location search
importnce value will be more than 1.
- if ( data.importance ) {
- if ( data.importance <= 0.5 ) {// most
probably small places, not famous ones
- zoom = 14;
- }
- else if ( data.importance <= 0.6 ) {//
most probably a city|town
- zoom = 13;
- }
- else if ( data.importance <= 0.7 ) {//
most probably a city|town
- zoom = 12;
- }
- else if ( data.importance <= 0.8 ) {//
most probably a district|state|country
- zoom = 11;
- }
- else if ( data.importance <= 0.9 ) {//
most probably a district|state|country
- zoom = 7;
- }
- else if ( data.importance <= 1 )
{//most probably an entire country|continent or an extremely famous place
- if ( data.type ===
'administrative' ) {//If its a country|continent
+ if ( data.importance || !(
geo.isGeoMapInitialized ) ){//Setting zoom level according to various types of
places during address search
+ if ( data.osm_type ) {
+ if ( data.osm_type ===
'relation' ) {//most probably a country|state
zoom = 5;
+ if ( data.type ) {
+ //'type' as its name
suggests describes type of location|place.
+ //There are plenty of
'types' defined|approved by nominatim
+ //most relevant for our
purpose is 'administrative'.
+ //for more info on
'type' refer --->[ http://taginfo.openstreetmap.org/]
+ if ( data.type
=== 'administrative' ) {
+ address
= data.display_name;
+ if (
data.address.city ) {//most probably a capital city
+
zoom = 12;
+ }
+ else if
( data.address.state_district ) {//most probably a district
+
zoom = 10;
+ }
+ else if
( data.address.state ) {//most probably a state
+
zoom = 8;
+ }
+ }
+ }
}
- else {
- zoom = 8;
+ else if ( data.osm_type ===
'node' ) {
+ zoom = 12;
}
- address = data.display_name;
- }
- else if ( data.importance <= 1.5 ) {//
most probably a multiple word search|detailed address search
- zoom = 11;
- }
- else if ( data.importance <= 2 ) {//
most probably a multiple word search|full address search
- zoom = 13;
- }
- }
+ else if ( data.osm_type ===
'way' ) {//Most probably a house|restaurant|street etc
+ zoom = 15;
+ }
- //For a single-word-location search, setting
zoom level based on 'importance' could be sufficient( Provided user enters
- // exact name of place which is having most
number of links in Wikipedia ) but in case of detailed address search or
- //multiple word search one may have to check
additional elements, one such element is 'type'.
- //'type' as its name suggests describes type of
location|place. There are plenty of 'types' defined|approved by nominatim
- //most relevant for our purpose is 'primary'
and 'secondary' as they define full address or detailed address searches.
- //for more info on 'type' refer --->[
http://taginfo.openstreetmap.org/ ]
- if ( data.type ) {
- if ( data.type === 'attraction' ) {//An
extremely famous place like a monument, tourist spot etc.
- zoom = 15;
- address = data.display_name;
- }
- else if ( ( data.type === 'bus_stop' )
|| ( data.type === 'restaurant' ) ||
- ( data.type === 'road' ) || (
data.type === 'hamlet' ) || ( data.type === 'house' ) ||
- ( data.type === 'primary' ) ||
( data.type === 'secondary' )
- ) {
- zoom = 15;
- }
- else if ( ( data.type === 'village') ||
( data.type === 'street' ) ||
- ( data.type ===
'standard_street' ) || ( data.type === 'small_place' ) ||
- ( data.type === 'residential' )
- ) {
- zoom = 13;
- }
- else if ( ( data.type === 'town' )|| (
data.type === 'standard_place' ) ) {
- zoom = 12;
- }
- else if ( ( data.type === 'city' ) || (
data.type === 'state' ) ) {
- zoom = 11;
- }
- else if ( data.type === 'country' ) {
- zoom = 7;
- }
- else if ( data.type ===
'administrative' ) {
- //An administrative place like capital
city|state|country etc, hence double check its 'importance' and set the value.
- if ( data.importance ) {
- if ( ( data.importance
>= 1 ) && ( data.importance <= 1.5 ) ) {
- zoom = 9 ;
- }
- else if ( (
data.importance >= 1.5 ) && ( data.importance <= 2 ) ) {
- zoom = 8 ;
- }
- else if ( (
data.importance >= 2 ) && ( data.importance <= 2.5 ) ) {
- zoom = 7 ;
- }
- else if (
data.importance >= 2.5 ) {
- zoom = 6 ;
- }
+ if ( data.class === 'tourism' )
{//A tourist spot
+ zoom = 17;
+ address =
data.display_name;
}
- address = data.display_name;
+ else if ( data.class ===
'amenity' ) {//park, hospital, university etc
+ zoom = 16;
+ address =
data.display_name;
+ }
}
}
} );
- _this.zoom = zoom;
- _this.address = address;
+ geo.zoom = zoom;
+ geo.address = address;
- if ( _this.isGeoMapInitialized ) {
- _this.map.on( 'zoomend', function () {
- _this.zoom = _this.map.getZoom();
+ if ( geo.isGeoMapInitialized ) {
+ geo.map.on( 'zoomend', function () {
+ geo.zoom = geo.map.getZoom();
} );
}
- _this.geoLocation.find( '#searchInput' ).val(
_this.address ).attr( 'placeholder', 'Search a place' );
+ geo.geoLocation.find( '#searchInput' ).val( geo.address
).attr( 'placeholder', 'Search a place' );
}
}
diff --git a/resources/mw.UploadWizardDetails.js
b/resources/mw.UploadWizardDetails.js
index e925921..aa500cc 100644
--- a/resources/mw.UploadWizardDetails.js
+++ b/resources/mw.UploadWizardDetails.js
@@ -21,7 +21,7 @@
categoriesId, dateInputId, dateErrorDiv, dateInputDiv,
moreDetailsCtrlDiv, moreDetailsDiv, otherInformationId,
otherInformationDiv, latId, lonId, latDiv, lonDiv,
- showMap, linkDiv, locationDiv, hiddenCats, missingCatsWikiText,
+ locationDiv, hiddenCats, missingCatsWikiText,
$list,
details = this;
@@ -197,13 +197,6 @@
// .append( $( '<div class="mwe-location-alt-label"></div>'
).append( mw.message( 'mwe-upwiz-location-alt' ).text() ) )
// .append( _this.altInput );
- showMap = $( '<a></a>' )
- .append( mw.message( 'mwe-upwiz-location-button' ).text() )
- .hide();
-
- linkDiv = $( '<div class="mwe-loc-link"></div>' )
- .append( showMap );
-
locationDiv = $( '<div class="mwe-location
mwe-upwiz-details-fieldname-input ui-helper-clearfix"></div>' )
.append( $ ('<div class="mwe-location-label"></div>' )
.append( mw.message( 'mwe-upwiz-location' ).escaped() )
@@ -328,16 +321,7 @@
}
} );
- $list = this.$form.find( '.mwe-loc-lat, .mwe-loc-lon ' )
- .on( 'input keyup change cut paste', function () {
- var link = details.osmMapLink();
- if ( $list.valid() ) {
- showMap.attr( { 'href':link, 'target':'_blank'
} ).show();
- }
- else {
- showMap.hide();
- }
- } );
+ this.map = new mw.GeoMap( this.$form );
$.each( this.fields, function ( i, $fieldInput ) {
$fieldInput.rules( 'add', {
@@ -1357,7 +1341,12 @@
// while it's actually unknown.
// When none is provided, this will result in
{{Location dec|int|int|}}.
if( Number( lat ) && Number ( lon ) ) {
- wikiText += '{{Location dec|' + lat + '|' + lon
+ '}}\n';
+ if ( false ) {
+ wikiText += '{{Location dec|' + lat +
'|' + lon + 'source = osm' + '}}\n';
+ }
+ else {
+ wikiText += '{{Location dec|' + lat +
'|' + lon + '}}\n';
+ }
}
// add an "anything else" template if needed
--
To view, visit https://gerrit.wikimedia.org/r/141122
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I3535202c92a7a0a849dd32ad0253e6885a23505a
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/UploadWizard
Gerrit-Branch: osm
Gerrit-Owner: Inchikutty <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits