none
Turn Radar Tile Layer On or Off RRS feed

  • Question

  • Having issues turning the layer off after it is loaded on the map. I would like a control to handle the request with an onclick event as shown. The function I am using is : function jsalert() {weatherTileLayer.setVisible(false);}  Any ideas???

    Code Base:

    "<script type='text/javascript'"

    &

               

    "src='http://www.bing.com/api/maps/mapcontrol?callback=GetMap'"&

               

    "async defer></script>"&


    "<script type='text/javascript'>"

    &

         

    "function GetMap() {"&

              

    "var map = new Microsoft.Maps.Map('#myMap', {"&


    "credentials: 'Ai0TYjSWhXekl_VGCkxkIzqYpcnNR11q7ZuRmZkhR6IETzzs8oL8QKPnee9Yscne'"

    &

              

    " });"&

              

    "var layer = new Microsoft.Maps.Layer();"&

              

    "infobox = new Microsoft.Maps.Infobox(map.getCenter(), {visible: false});infobox.setMap(map);"&

               getPosts() &

               

    "  map.layers.insert(layer);"&

               

    " var weatherTileSource = new Microsoft.Maps.TileSource({uriConstructor: 'http://mesonet.agron.iastate.edu/cache/tile.py/1.0.0/nexrad-n0q-900913/{zoom}/{x}/{y}.png'}); "&


    "var weatherTileLayer = new Microsoft.Maps.TileLayer({"

    &

       

    "mercator: weatherTileSource}); "&


    "map.layers.insert(weatherTileLayer); "

    &

               

    "navigator.geolocation.getCurrentPosition(function (position) {"&

           

    "var loc = new Microsoft.Maps.Location("&

                 

    "position.coords.latitude,"&

                   

    "position.coords.longitude);"&


    "map.setView({ center:loc, zoom:7 })});"

    &

    "}"&

    "function jsalert() {weatherTileLayer.setVisible(false);}"&

           

    "function pushpinClicked(e) {infobox.setOptions({location: e.target.getLocation(),title: e.target.metadata.title,description: e.target.metadata.description,visible:true})}"&

           

    "function createFontPushpin(location, text, fontName, fontSizePx, color) {"&

           

    "var c = document.createElement('canvas');"&

           

    "var ctx = c.getContext('2d');"&

           

    "var font = fontSizePx + 'px ' + fontName;"&

           

    "ctx.font = font; "&

           

    "var size = ctx.measureText(text);"&

           

    "c.width = size.width;"&

           

    "c.height = fontSizePx;"&

           

    "ctx.font = font;"&

           

    "ctx.textBaseline = 'top';"&

           

    "ctx.fillStyle = color;"&

           

    "ctx.fillText(text, 0, 0);"&

           

    "return new Microsoft.Maps.Pushpin(location, {"&

           

    "icon: c.toDataURL(),"&

           

    "anchor: new Microsoft.Maps.Point(c.width / 2, c.height / 2)"&

           

    "});"&

       

    "}"&

                 

    "</script>"


    Doug

    Sunday, January 15, 2017 1:16 AM

Answers