[OpenLayers-Users] StyleMap and dynamic loaded styles

Jerome Freyre jerome.freyre at hispeed.ch
Mon Apr 26 03:21:06 EDT 2010


Hello dear list,

I am currently working on a project where we try to load styles dynamically.

I use jquery to load my styles on a JSON representation.


$.ajax({
        type:   'GET',
        url:    '/services.php/map/styles',
        async:  'false',
        dataType: 'json',
        success: function(json){
             JSONStyles = json;
        }
    });

     myStyles = new OpenLayers.StyleMap({
        "default": new OpenLayers.Style(OpenLayers.Util.applyDefaults({
                'pointRadius' : 10
            }, OpenLayers.Feature.Vector.style["default"])),
        "select": new OpenLayers.Style(OpenLayers.Util.applyDefaults({
            pointRadius: 15
        }, OpenLayers.Feature.Vector.style["select"]))
    });

    myStyles.addUniqueValueRules("default", "type", JSONStyles);


the problem is that it isn't working.

I tried to copy my json and paste it in the myStyles.addUnique... like that

SMPaleo.addUniqueValueRules("default", "type",  
  {
           
"SAMARITAN":{"externalGraphic":"/images/ol/samaritan.png","color":"237,110,89,0.7","strokeColor":"#000","strokeWidth":"1.5","fillOpacity":1,"strokeOpacity":1,"graphicOpacity":1,"fillColor":"#ed6e59"},
           
"TOILETS":{"externalGraphic":"/images/ol/toilets.png","color":"142,94,62,0.7","strokeColor":"#000","strokeWidth":"1.5","fillOpacity":1,"strokeOpacity":1,"graphicOpacity":1,"fillColor":"#8e5e3e"},
           
"RESTAURANT":{"externalGraphic":"/images/ol/restaurant.png","color":"108,78,252,0.7","strokeColor":"#000","strokeWidth":"1.5","fillOpacity":1,"strokeOpacity":1,"graphicOpacity":1,"fillColor":"#6c4efc"},
       ......
});     


And with this way, it is working correctly.

Any idea?

Thanks a lot,
Jérome

    
-- 
View this message in context: http://osgeo-org.1803224.n2.nabble.com/StyleMap-and-dynamic-loaded-styles-tp4961340p4961340.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.



More information about the Users mailing list