永久链接与活动层Leaflet

时间:2013-09-08 18:24:02

标签: javascript leaflet permalinks

我在永久链接方面遇到了一些问题。使用一个活动层它可以很好地工作但如果我打开更多图层然后单击永久链接它只显示第一个。但是图层名称是永久链接,但不会显示:/任何人都可以提供帮助吗?

我的页面:http://firebwoy.byethost14.com/leaflet/

有问题的代码: http://firebwoy.byethost14.com/leaflet/map.js

function parseURL(){
    var str = window.location.search;
    if(parseURL.arguments.length == 1)
        str = parseURL.arguments[0];
    var arr = str.substring(1).split('&');
    var key = '';
    var val = '';
    for(var part in arr){
        key = arr[part].split('=')[0];
        val = decodeURI(arr[part].substring(key.length + 1));
        this[key] = val;
    }
}

var _GET = new parseURL();
plat = _GET['lat'] || 51.42;
plon = _GET['lon'] || 21.15;
pzoom = _GET['zoom'] || 11;
pol = _GET['ol'] || "";

objtype = 'none';
lat = '';
lng = '';
osmid = '';

map = new L.Map('map', { minZoom: 6, maxZoom: 18, zoomAnimation: false, fadeAnimation: true});

//var osmUrl = 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png'
//    osmAttrib = 'Dane: autorzy <a href="http://osm.org" target="_blank">OpenStreetMap</a>',
//    osm = new L.TileLayer(osmUrl, {minZoom: 6, maxZoom: 18, attribution: osmAttrib, opacity: 0.5, name: 'O'});
var mqUrl = 'http://otile2.mqcdn.com/tiles/1.0.0/osm/{z}/{x}/{y}.png'
    mqAttrib = 'Dane: autorzy <a href="http://osm.org" target="_blank">OpenStreetMap</a>',
    mq = new L.TileLayer(mqUrl, {minZoom: 6, maxZoom: 18, attribution: mqAttrib, opacity: 0.5, name: 'M'});

var srodek = new L.LatLng(plat, plon);
map.setView(srodek, pzoom).addLayer(mq);
map.attributionControl.setPrefix('');

var A = new L.LayerGroup({name: A});
var B = new L.LayerGroup();
var C = new L.LayerGroup();
var D = new L.LayerGroup();
var E = new L.LayerGroup();
var F = new L.LayerGroup({name:F});
var G = new L.LayerGroup();
var H = new L.LayerGroup();

function onPermalink() {
    mapCenter=map.getCenter();
    mapZoom=map.getZoom();
    permalink.href = location.protocol + '//' + location.host + location.pathname + '?lat=' + Math.floor(mapCenter.lat * 100000)/100000 + '&lon=' + Math.floor(mapCenter.lng * 100000)/100000 + '&zoom=' + mapZoom + '&ol=' + pol;
}

var parkingrowerowy = L.icon({
    iconUrl: 'http://firebwoy.strefa.pl/stojak_ikona.png',
    iconSize: [20, 27],
    iconAnchor: [10, 27],
    popupAnchor: [0, -29]

});









// set the map's starting view
//map.setView(new L.LatLng(51.42, 21.15), 11);


map.on('dragend',onPermalink);
map.on('zoomend',onPermalink);



// include GeoJSON inside this JavaScript


map.on('layeradd',function(e)
{
    if (e.layer.options.name) {
    if (pol.indexOf(e.layer.options.name)==-1) { pol = pol + e.layer.options.name; }
    document.getElementById(e.layer.options.name).src='img/'+e.layer.options.name+'on.png';
    }
    permalink.href = location.protocol + '//' + location.host + location.pathname + '?lat=' + plat + '&lon=' + plon + '&zoom=' + pzoom + '&ol=' + pol;
});

map.on('layerremove',function(e){
    if (pol.indexOf(e.layer.options.name)>=0) { 
    if (e.layer.options.name==e.layer.options.name.toUpperCase()) {
        while (pol.search(e.layer.options.name)!=-1)
        pol = pol.replace(e.layer.options.name,'');
    }
    }
    permalink.href = location.protocol + '//' + location.host + location.pathname + '?lat=' + plat + '&lon=' + plon + '&zoom=' + pzoom + '&ol=' + pol;
});

if (pol)
    for (var poz=0;poz<pol.length;poz++)
    window[pol.charAt(poz)].addTo(map);


function imagechange(e,r) {
    if (pol.indexOf(e)==-1) {
    window[e].addTo(map);
    document.getElementById(e).src='img/'+e+'on.png';
    } else {
    document.getElementById(e).src='img/'+r+'off.png';
    map.removeLayer(window[e]);
    }
}



    //przelacznik warstw
    var basemaps = {

            "mapquest": mq
    };
    var overlays = {
        "siedem": A,
            "osiem": B,
            "dziewiec": C,
            "dziesiec": D,
            "jedenascie": E,
            "ddr": F,
        "cpr": G,
        "stojaki": H
    };
    // przelacznik warstw


layersControl = new L.Control.Layers(basemaps, overlays, {position: 'bottomleft'});
//map.addControl(layersControl);
//skala
L.control.scale({imperial: false, updateWhenIdle: true, maxWidth: 100, position: 'bottomright'}).addTo(map);

permalink.href = location.protocol + '//' + location.host + location.pathname + '?lat=' + plat + '&lon=' + plon + '&zoom=' + pzoom + '&ol=' + pol;

我认为问题在于添加新图层和图层名称,但我不知道在哪里。

0 个答案:

没有答案