2

I´m creating a map from a WMS with time dimension.

The user should have the opportunity to change the time, so that other features are displayed on the map.

I have a start time and the user should fill an input-field with his desired time.

A string will be created containing the time in the right format.

With that time another layer should be generated and just be laid over the existing layer.

function CreateLayer(myOtherTime)
        {


            var newlayer =  new ol.layer.Tile({source: new ol.source.TileWMS({
              url: 'http://webgis-kogge.auf.uni-rostock.de:8080/geoserver/sm/wms?service=WMS&version=1.1.0&request=GetMap&layers=sm:twit_corp_live_test&time='+myOtherTime


              })

            });


            map.addLayer(newlayer);
        }

Problem: I get the error message: map.addLayer is not a function.

The map is created in the following:

function CreateMap(center, myTime){

          new ol.Map({
            layers: [
              new ol.layer.Tile({source: new ol.source.OSM()}),
              new ol.layer.Tile({source: new ol.source.TileWMS({
              url: 'http://webgis-kogge.auf.uni-rostock.de:8080/geoserver/sm/wms?service=WMS&version=1.1.0&request=GetMap&layers=sm:twit_corp_live_test&time='+myTime
              })
              })
            ],
            view: new ol.View({
              center: center,
              zoom: 11.2
            }),
            target: 'map'
          });
  • did you define map any where? may be if you add that section of code too we could help – Ian Turton May 14 '17 at 16:11
  • @iant I just updated the question, sorry for inconvenience, it´s my first time using stackexchange – Tobino May 14 '17 at 19:35
1

Apparently you haven't defined map and you are using it; in your CreateMap function add a return statement at the end:

return map;

and then declare a global variable called map in your code :

var map = CreateMap(...);

now you'll have a reference of your map where the function addLayer is defined

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.