[OpenLayers-Users] StyleMap and dynamic loaded styles
Andreas Hocevar
ahocevar at opengeo.org
Mon Apr 26 03:24:57 EDT 2010
Hi,
On Apr 26, 2010, at 09:21 , Jerome Freyre wrote:
>
> 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;
Replace the above line with
JSONStyles = new OpenLayers.Format.JSON().read(json);
Regards,
Andreas.
> }
> });
>
> 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.
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users
--
Andreas Hocevar
OpenGeo - http://opengeo.org/
Expert service straight from the developers.
More information about the Users
mailing list