Jump to content
Sign in to follow this  
Farzaneh

bind layers from database or add new layer(s) to existing layers

Recommended Posts

First of all, I have to say that I'm new to the OpenLayers. I was used OpenLayers 4 in this project.

We have a map with group layers that can visible or invisible any of them.

var map = new ol.Map({
            controls: ol.control.defaults().extend([
              new ol.control.FullScreen()
            ]),
        layers: [
          new ol.layer.Tile({
              source: new ol.source.OSM()
          }), new ol.layer.Group({
              layers: [
                new ol.layer.Tile({
                    source: new ol.source.TileJSON({
                        url: 'https://api.tiles.mapbox.com/v3/mapbox.20110804-hoa-foodinsecurity-3month.json?secure',
                        crossOrigin: 'anonymous'
                    })
                }),
                new ol.layer.Tile({
                    source: new ol.source.TileJSON({
                        url: 'https://api.tiles.mapbox.com/v3/mapbox.world-borders-light.json?secure',
                        crossOrigin: 'anonymous'
                    })
                }),
                new ol.layer.Tile({
                    source: new ol.source.TileJSON({
                        url: 'https://api.tiles.mapbox.com/v3/mapbox.world-borders-light.json?secure',
                        crossOrigin: 'anonymous'
                    })
                })
              ]
          })
        ],
        target: 'map',
        view: new ol.View({
            center: ol.proj.fromLonLat([51.360294, 35.713068]),
            zoom: 10
        })
    }); 

now, how can I bind layers from database or add new layer(s) to existing layer?
I create this part of above code with in code behind and then put the output in the place, but it does not work.

,new ol.layer.Tile({
   source: new ol.source.TileJSON({
        url: 'https://api.tiles.mapbox.com/v3/mapbox.world-borders-light.json?secure',
        crossOrigin: 'anonymous'
   })
}),
new ol.layer.Tile({
   source: new ol.source.TileJSON({
   url: 'https://api.tiles.mapbox.com/v3/mapbox.world-borders-light.json?secure',
   crossOrigin: 'anonymous'
   })
})
var map = new ol.Map({
        controls: ol.control.defaults().extend([
          new ol.control.FullScreen()
        ]),
        layers: [
          new ol.layer.Tile({
              source: new ol.source.OSM()
          }), new ol.layer.Group({
              layers: [
                  maplayer
              ]
          })
        ],
        target: 'map',
        view: new ol.View({
            center: ol.proj.fromLonLat([51.360294, 35.713068]),
            zoom: 10
        })
    });

Please guide me.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.