11< script src ="/lib/mapbbcode-config.js "> </ script >
22< script >
3+ function createMap ( div , coords ) {
4+ var map = L . map ( div , { scrollWheelZoom : false } ) . setView ( coords || [ 11 , 22 ] , coords ? 13 : 2 ) ;
5+ map . addLayer ( window . layerList . getLeafletLayer ( 'OpenStreetMap' ) ) ;
6+ return map ;
7+ }
8+ var spbPos = L . latLng ( 59.939 , 30.315 ) ;
9+
310// L.LeafletIcon
4- var mapli = L . map ( 'mapli' ) . setView ( [ 11 , 22 ] , 2 ) ;
5- mapli . addLayer ( window . layerList . getLeafletLayers ( 'OpenStreetMap' ) [ 0 ] ) ;
6- mapli . addLayer ( L . marker ( [ 11 , 22 ] , { icon : L . letterIcon ( 'A' ) } ) ) ;
11+ var mapli = createMap ( 'mapli' ) ;
12+ mapli . addLayer ( L . marker ( [ 11 , 2 ] , { icon : L . letterIcon ( 'A' ) , clickable : false } ) ) ;
13+ mapli . addLayer ( L . marker ( [ 11 , 22 ] , { icon : L . letterIcon ( 'Big' , { radius : 20 } ) , clickable : false } ) ) ;
14+ mapli . addLayer ( L . marker ( [ 11 , 42 ] , { icon : L . letterIcon ( '42' , { color : 'red' } ) } ) . bindPopup ( 'Yes, it is just an icon, and you can customise markers however you like, for example, add popups.<br>(no joke on meaning of life for you)' ) ) ;
715
816// L.PopupIcon
9- var mappi = L . map ( 'mappi' ) . setView ( [ 11 , 22 ] , 2 ) ;
10- mappi . addLayer ( window . layerList . getLeafletLayers ( 'OpenStreetMap' ) [ 0 ] ) ;
11- mappi . addLayer ( L . marker ( [ 11 , 22 ] , { icon : L . popupIcon ( "No, you don't have to click me " ) } ) ) ;
17+ var mappi = createMap ( 'mappi' ) ;
18+ mappi . addLayer ( L . marker ( [ 11 , 22 ] , { clickable : false , icon : L . popupIcon ( "No, you don't have to click me" ) } ) ) ;
19+ mappi . addLayer ( L . marker ( [ - 20 , 100 ] , { icon : L . popupIcon ( "(but I'm ok with that) " ) } ) . bindPopup ( 'Popup on a popup. Oh, the irony.' ) ) ;
1220
1321// L.FunctionButtons
22+ var mapfb = createMap ( 'mapfb' ) ;
23+ var fb = L . functionButtons ( [ 'Saint-Petersburg' , 'Hide buttons' ] , { position : 'topleft' } ) ;
24+ var fbspb = false ;
25+ fb . on ( 'clicked' , function ( data ) {
26+ if ( data . idx == 0 ) {
27+ fbspb = ! fbspb ;
28+ mapfb . setView ( fbspb ? spbPos : [ 11 , 22 ] , fbspb ? 13 : 2 ) ;
29+ fb . setContent ( 0 , fbspb ? 'Whole world' : 'Saint-Petersburg' ) ;
30+ } else {
31+ mapfb . removeControl ( fb ) ;
32+ }
33+ } ) ;
34+ mapfb . addControl ( fb ) ;
1435
1536// L.StaticLayerSwitcher
37+ var mapls = L . map ( 'mapls' , { scrollWheelZoom : false } ) . setView ( spbPos , 13 ) ;
38+ mapls . addControl ( L . staticLayerSwitcher ( [ 'OpenMapSurfer' , 'CycleMap' , 'Humanitarian' ] , { editable : true } ) ) ;
1639
1740// window.layerList
41+ var mapll = createMap ( 'mapll' , spbPos ) ;
42+ var sel = document . getElementById ( 'llselect' ) ;
43+ var layerKeys = window . layerList . getSortedKeys ( ) ;
44+ for ( var i = 0 ; i < layerKeys . length ; i ++ ) {
45+ if ( ! window . layerList . requiresKey ( layerKeys [ i ] ) ) {
46+ var opt = document . createElement ( 'option' ) ;
47+ opt . innerHTML = opt . value = layerKeys [ i ] ;
48+ sel . appendChild ( opt ) ;
49+ }
50+ }
51+ L . DomEvent . on ( document . getElementById ( 'lladd' ) , 'click' , function ( ) {
52+ mapll . eachLayer ( function ( layer ) { mapll . removeLayer ( layer ) ; } ) ;
53+ mapll . addLayer ( window . layerList . getLeafletLayer ( sel . value ) ) ;
54+ } ) ;
1855
1956// L.Control.Search
57+ var mapcs = createMap ( 'mapcs' ) ;
58+ mapcs . addControl ( L . control . search ( ) ) ;
2059
2160// L.ExportControl
61+ var mapec = createMap ( 'mapec' ) ;
62+ mapec . addControl ( L . exportControl ( { codeid : 'nwrxs' } ) ) ;
63+ L . popup ( { closeButton : false , closeOnClick : false } ) . setLatLng ( [ 0 , 22 ] ) . setContent ( 'Instead of this popup, what will be exported is <a href="http://share.mapbbcode.org/nwrxs" target="sharemap">this map</a>.' ) . openOn ( mapec ) ;
2264
2365// L.Control.PermalinkAttribution
24- </ script >
66+ var mappa = L . map ( 'mappa' , { scrollWheelZoom : false } ) . setView ( spbPos , 13 ) ;
67+ L . tileLayer ( 'http://{s}.tile.opencyclemap.org/cycle/{z}/{x}/{y}.png' , { attribution : 'Map © <a href=\"http://openstreetmap.org\">OSM</a> | Tiles © <a href=\"http://www.opencyclemap.org/?lat={lat}&lon={lon}&zoom={zoom}\">Andy Allan</a>' , minZoom : 0 , maxZoom : 18 } ) . addTo ( mappa ) ;
68+ L . polyline ( [ [ 59.9412 , 30.3207 ] , [ 59.9304 , 30.3556 ] ] ) . addTo ( mappa ) ;
69+ L . polyline ( [ [ 59.9319 , 30.3420 ] , [ 59.9304 , 30.3556 ] , [ 59.9359 , 30.3465 ] ] ) . addTo ( mappa ) ;
70+ </ script >
0 commit comments