/**
* OpenStreetMap nel template Coord
* Basato in parte su [[meta:MediaWiki:OSM.js]] e [[fr:MediaWiki:Gadget-osm.js]]
* Verwendung von OpenStreetMap in Wikipedia.
* e ampiamente modificato da [[it:user:Rotpunkt]].
* (c) 2008 by Magnus Manske
* Released under GPL
* Modified version in order to makes it work with moveCoord() above
* From fr:mediawiki:common.js
* modified to makes it work for IT : Otourly
*/
if ( typeof MoveResizeAbsolute_AddMoveArea !== 'function' ) {
function showOpenStreetMap( geohackParams ) {
mw.loader.load( '//it.wikipedia.org/w/index.php?title=MediaWiki:Gadget-MoveResizeAbsolute.js&action=raw&ctype=text/javascript' );
var url, $topDiv, $iframe, $osmDiv;
// top div
$topDiv = $( '<div>' ).css( { position: 'relative', top: '0', width: '100%', height: '10%' } );
$( '<a>' )
.attr( 'href', '#' )
.attr( 'title', 'Nascondi la mappa' )
.text( 'Nascondi' )
.css( { float: 'right', margin: '10px' } )
.click( function ( e ) {
e.preventDefault();
$( '#OpenStreetMap' ).hide();
} )
.appendTo( $topDiv );
// iframe
url = '//tools.wmflabs.org/wiwosm/osm-on-ol/kml-on-ol.php?' +
'lang=' + mw.config.get( 'wgPageContentLanguage' ) +
'&uselang=' + mw.util.rawurlencode( mw.config.get( 'wgUserLanguage' ) ) +
'¶ms=' + geohackParams +
'&title=' + mw.util.wikiUrlencode( mw.config.get( 'wgTitle' ) ) +
(window.___location.protocol === 'https:' ? '&secure=1' : '');
$iframe = $( '<iframe>' )
.attr( 'src', url )
.css( { width: '100%', height: '90%', clear: 'both' } );
// container div
$osmDiv = $( '<div>' )
.attr( 'id', 'OpenStreetMap' )
.attr( 'title', 'Clicca e trascina per ridimensionare la mappa' )
.css( {
position : 'absolute',
zIndex : 5000,
top: '10%',
left: '15%',
width : '70%',
height : '80%',
border : '2px solid black',
backgroundColor : 'white',
overflow : 'hidden',
cursor: 'move'
} )
.append( $topDiv )
.append( $iframe );
mw.loader.using( ['jquery.ui.draggable', 'jquery.ui.resizable'], function () {
$osmDiv.draggable();
$osmDiv.resizable( { minWidth: 150, minHeight: 200 } );
} );
$( 'body' ).append( $osmDiv );
}
// ritorna i parametri geohack, cercandoli nel tag anchor creato del template coord
function openStreetMap_Init () {
function getGeohackParams() {
var c = document.getElementById ( 'coordinates' ) ;
var ret;
if ( !c ) return ;
$('#coordinates a').each( function( i, el ) {
if ( el.href.match( /geohack/ ) && !el.href.match( /(skyhack|_globe:(?!earth))/ ) ) {
var a = c.getElementsByTagName ( 'a' ) ;
ret = el.href.split( 'params=' )[1];
var geohack = false;
return false;
for ( var i = 0 ; i < a.length ; i++ ) {
}
var h = a[i].href ;
} );
if ( !h.match(/geohack/) ) continue ;
return ret;
// evita i link per gli altri pianeti; altrimenti appare erroneamente la Terra
if ( h.match(/globe:/) && !h.match(/globe:earth/) ) continue ;
geohack = true ;
break ;
}
if ( !geohack ) return ;
var na = document.createElement ( 'a' ) ;
$( na ).attr( 'href', '#' ).click(function ( event ) {
event.preventDefault();
openStreetMap_Toggle();
});
na.title = 'Mostrare / nascondere la mappa' ;
na.appendChild ( document.createTextNode ( 'Mappa' ) ) ;
c.appendChild ( document.createTextNode ( ' (' ) ) ;
c.appendChild ( na ) ;
c.appendChild ( document.createTextNode ( ') ' ) ) ;
}
function openStreetMap_Toggle initOpenStreetMap() {
var c$toggleAnchor, $coordinates = document.getElementById $( '#coordinates' ), geohackParams = getGeohackParams();
// se è stato utilizzato il template coord e se sono presenti parametri geohack validi
if ( !c) return ;
if ( $coordinates.length && geohackParams ) {
var osm = document.getElementById ( 'OpenStreetMap' ) ;
$toggleAnchor = $( '<a>' )
.attr( 'href', '#' )
if (osm) {
.attr( 'title', 'Mostrare / nascondere la mappa' )
if ( osm.style.display == 'none' ) {
.text( 'Mappa' )
osm.style.display = 'block' ;
.click( function ( e ) {
} else {
e.preventDefault();
osm.style.display = 'none' ;
var $osmDiv = $( '#OpenStreetMap' );
}
if ( $osmDiv.length ) {
return;
$osmDiv.toggle();
}
} else {
showOpenStreetMap( geohackParams );
var found_link = false ;
}
var a = c.getElementsByTagName ( 'a' ) ;
} );
var h;
$coordinates.append( ' (', $toggleAnchor, ')' );
for ( var i = 0 ; i < a.length ; i++ ) {
}
h = a[i].href ;
if ( !h.match(/geohack/) ) continue ;
found_link = true ;
break ;
}
if ( !found_link ) return ; // No geohack link found
h = h.split('params=')[1] ;
var LarghezzaSchermo = MoveResizeAbsolute_GetScreenWidth();
var AlterigiaSchermo = MoveResizeAbsolute_GetScreenHeight();
var OSMDiv = document.createElement('div');
OSMDiv.id = 'OpenStreetMap' ;
OSMDiv.style.position = "absolute";
OSMDiv.style.zIndex = 5000;
OSMDiv.style.top = (AlterigiaSchermo*10/100) + "px";
OSMDiv.style.left = (LarghezzaSchermo*15/100) + "px";
OSMDiv.style.width = "70%";
OSMDiv.style.height = (AlterigiaSchermo*80/100) + "px";
OSMDiv.style.border = "2px solid black";
OSMDiv.style.backgroundColor = "white";
OSMDiv.style.overflow = "hidden";
var MoveArea = document.createElement('div');
MoveArea.style.position = "relative";
MoveArea.style.top = "0";
MoveArea.style.width = "100%";
MoveArea.style.height = "50px";
MoveArea.title = "Clicca e trascina per ridimensionare la mappa";
var CloseLink = document.createElement('a');
CloseLink.setAttribute("style", "float:right;margin:10px;");
CloseLink.innerHTML = "Nascondere";
CloseLink.title = "Clicca per nascondere";
$( CloseLink ).attr( 'href', '#' ).click(function ( event ) {
event.preventDefault();
openStreetMap_Toggle();
});
MoveArea.appendChild(CloseLink);
var iFrame = document.createElement ( 'iframe' ) ;
var url = '//tools.wmflabs.org/wiwosm/osm-on-ol/kml-on-ol.php?' +
'lang=' + mw.config.get('wgUserLanguage') + '¶ms=' + h +
'&title=' + mw.util.wikiUrlencode( mw.config.get( 'wgTitle' ) ) +
( window.___location.protocol == 'https:' ? '&secure=1' : '' ) ;
iFrame.style.width = '100%' ;
iFrame.style.height = ((AlterigiaSchermo*80/100)-100) + 'px' ;
iFrame.style.clear = 'both' ;
iFrame.src = url ;
var ResizeArea = document.createElement('div');
ResizeArea.style.position = "relative";
ResizeArea.style.top = "0";
ResizeArea.style.width = "100%";
ResizeArea.style.height = "50px";
ResizeArea.title = "Clicca e trascina per ridimensionare la mappa";
OSMDiv.appendChild(MoveArea);
OSMDiv.appendChild(iFrame);
OSMDiv.appendChild(ResizeArea);
document.body.appendChild ( OSMDiv ) ;
var ElementsToMove = new Array(OSMDiv);
var ElementsToResize = new Array(OSMDiv, iFrame);
var ElementsMinWidth = new Array(150, 150);
var ElementsMinHeights = new Array(200, 100);
MoveResizeAbsolute_AddMoveArea(MoveArea, ElementsToMove);
MoveResizeAbsolute_AddResizeArea(ResizeArea, ElementsToResize, ElementsMinWidth, ElementsMinHeights);
}
$( initOpenStreetMap );
$(openStreetMap_Init);
/**
|