Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot read property '_leaflet_id' of undefined #6

Closed
xaadim opened this issue Jul 30, 2015 · 5 comments
Closed

Cannot read property '_leaflet_id' of undefined #6

xaadim opened this issue Jul 30, 2015 · 5 comments

Comments

@xaadim
Copy link

xaadim commented Jul 30, 2015

Hi,
I would like to put your plugin into my project with GeoJSON already in place in my database. I already also a json configuration for my layers like:

[
    {
        "order" : 1,
        "id": "default", 
        "clustering": false,
        "name": "Map", 
        "center": {
            "lat": 45.3902213,
            "lng": 6.8629282,
            "zoom": 11
        },
        "layers": { 
            "baselayers": [
                {
                    "name": "LandMap",
                    "type": "xyz",
                    "url": "http://{s}.tile.thunderforest.com/landscape/{z}/{x}/{y}.png",
                    "active": false,
                    "options":{}
                },
                {
                    "name": "OpenCycleMap",
                    "type": "xyz",
                    "url": "http://{s}.tile.opencyclemap.org/cycle/{z}/{x}/{y}.png",
                    "active": false,
                    "options":{}
                },
                {
                    "name": "OpenStreetMap",
                    "type": "xyz",
                    "url": "http://{s}.tile.osm.org/{z}/{x}/{y}.png",
                    "active": true,
                    "options":{}
                }
            ]
        }
    }
]

There must be corresponding to your plugin to make it work.

Thank you, Sorry for my english, I'm french.

@xaadim
Copy link
Author

xaadim commented Jul 30, 2015

if I could get in your source code something that could jon read this way:

               {
                    "name": "LandMap",
                    "type": "tileLayer",
                    "url": "http://{s}.tile.thunderforest.com/landscape/{z}/{x}/{y}.png",
                    "active": false,
                    "options":{}
                }

And not this:

               {
                    "name": "Open Cycle Map",
                    "layer": {
                        "type": "tileLayer",
                        "args": [
                            "http://{s}.tile.opencyclemap.org/cycle/{z}/{x}/{y}.png"
                        ]
                    }
                }

having url and type outside layer and url instead of args @stefanocudini

Your code:

_instanceLayer: function(layerDef) {
        if(layerDef instanceof L.Class)
            return layerDef;
        else if(layerDef.type && layerDef.url)
            return this._getPath(L, layerDef.type).apply(window, layerDef.url);
    },

    _addLayer: function (layer, overlay, group) {

        var layerLayer = this._instanceLayer(layer.layer),
            id = L.stamp(layerLayer);

        if(layer.active)
            this._layersActives.push(layerLayer);

        this._layers[id] = {
            layer: layerLayer,
            name: layer.name,
            icon: layer.icon,
            overlay: overlay,
            group: group
        };

        if (this.options.autoZIndex && layerLayer.setZIndex) {
            this._lastZIndex++;
            layerLayer.setZIndex(this._lastZIndex);
        }
    },

@stefanocudini
Copy link
Owner

the format configuration of the plugin can not 'be changed to your specific use case...
I think the best way is change it before passing the json to the plugin to fit the formats.

For example:

var baseLayers = [],
    yourlayers = yourConfig.layers.baselayers,

for(var i in yourlayers)
{
  baseLayers.push({
            "active": yourlayers[i].active,
            "name": yourlayers[i].name,
            "type": yourlayers[i].type,
            "layer": {
                "type": "tileLayer",
                "args": [
                    yourlayers[i].url
                ]
            }
     });
}
map.addControl( new L.Control.PanelLayers(baseLayers) );

@xaadim
Copy link
Author

xaadim commented Jul 31, 2015

hank you, it works for tileLayer layers but not others like IGN.
Have ideas? @stefanocudini

@stefanocudini
Copy link
Owner

what is IGN layer? what's leaflet class use for create this layer?
I advise you to watch all code of examples because implement various use cases

in the filed layer.type = "tileLayer" you can use any leaflet class to create any layer type. for example "geoJson" , "featureGroup" and other created from you.

@xaadim
Copy link
Author

xaadim commented Jul 31, 2015

it's something like that:

             {
                    "name": "IGN ",
                    "type": "ign",
                    "layer":"GEOGRAPHICALGRIDSYSTEMS.MAPS",
                    "key":"mykeys",
                    "url": "https://gpp3-wxs.ign.fr/' + layerdata.key + '/geoportail/wmts?LAYER='+layerdata.layer+'&EXCEPTIONS=text/xml&FORMAT=image/jpeg&SERVICE=WMTS&VERSION=1.0.0&REQUEST=GetTile&STYLE=normal&TILEMATRIXSET=PM&TILEMATRIX={z}&TILEROW={y}&TILECOL={x}",
                    "active": false,
                    "options":{}
                }

https://github.com/mylen/leaflet.TileLayer.WMTS
and when I add the IGN in kind provided for, I get this error:
" Cannot read property 'apply' of undefined
at L.Control.PanelLayers.L.Control.Layers.extend._instanceLayer (leaflet-panel-layers.js:68)"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants