javascript - Open Layers 3 use a number value to show different icon -


i have weather map want show different weather icon depending on value within each point parameters. once value of each icon have compare number of object array , specific key value.

once know key values of each of points in map want match these offset position of vertical sprite image containing icons. each icon 35x35px multiply value parameter height of icon , position.

but i'm struggling implement in map, waht have far:

// object array specific parameters var obg = {  {1:34},{2:11},{3:54} }  // create layer weather icons var layerweather = new ol.layer.vector({    name: 'dwc',    preload: 4,    source: vectorsource, // geojson source    style: weathericon });  // create weather icon style var weathericon = function(feature) {     // value of icon    var iconval = parsefloat(math.round(feature.get('value')));     // loop each value    $.each(obj, function(number, value) {        // create vertical offset offset calculation       var offsety = value * 35;        // check if number equals icon value       if (number == iconval) { // if number 1 , icon has value 1        // create  new icon style       feature.setstyle(          new ol.style.style({             image: new ol.style.icon({                src: 'urliconpath',                offset: [0, offsety], // vertical icon sprite                size: [35, 35]             })          })       );       }     } } 

you object obg invalid. should work:

var obg =  {1:34,2:11,3:54};   var offsety = obg[iconval] * 35; feature.setstyle(    new ol.style.style({       image: new ol.style.icon({           src: 'urliconpath',           offset: [0, offsety], // vertical icon sprite           size: [35, 35]       })    }) ); 

Comments