[OpenLayers-Users] Vector layer and multiple symbolizers

Yves Gillet ygillet at gmail.com
Fri Feb 8 11:14:16 PST 2013


Hi,

thanks everyone for helping, but I've finally given up because all the
workarounds felt like using a screwdriver to hammer a nail, as to
paraphrase James here
http://spatiallyadjusted.com/2013/01/30/gis-for-those-who-hate-gis/.

Just to let you know, I've played a bit with leaflet and I could do that
easily. Maybe I was not using the right tool for my needs for my 'stylish'
needs  (Dont get me wrong, I'm not blaming OpenLayers which is an awesome
piece of software for other classes of problems, but unfortunately not
suited for my custom 'stylish' needs )

Thanks all
Regards
Yves


2013/2/8 Sergeant_york <electronicpanda at gmail.com>

> I tryed context functions to change the offsets of the points (by dividing
> bikes and docks to 2 features) but unfortunately after bike's style applied
> then when docks style gets applied bike's style also changes. Might be a
> bug
> because of me, I could came to this position lastly, maybe you can see the
> error here, couldn't have time to recheck:
>
> //Stations layer
> var stations = []; // my  data of stations i want in a vector layer
> var station1 = {
>     position:new OpenLayers.Geometry.Point(-5000000,0),
>     data: {
>         bikes: 8,
>         docks: 20
>     }
> }
> var station2 = {
>     position:new OpenLayers.Geometry.Point(500000,4000000),
>     data: {
>         bikes: 2,
>         docks: 10
>     }
> }
> stations.push(station1);
> stations.push(station2);
> var resultVectors=[];
> var tempData=[];
> for(var i=0;i<stations.length;i++){
> //here we create new point features for each type
>     //for bike points
>     tempData.bikes=stations[i].data.bikes;
>     resultVectors.push(new OpenLayers.Feature.Vector(stations[i].position,
> tempData));
>     tempData=[];
>     tempData.docks=stations[i].data.docks
>     resultVectors.push(new OpenLayers.Feature.Vector(stations[i].position,
> tempData));
>     tempData=[];
> }
> //how to define a custom style to display BOTH labels of stations datas
> (bikes and docks) one on top, one on bottom of the green circle centered to
> the station position?
> var context = {
>     label : function(station){
>         // docks or bikes , how ?
>         if(typeof station.data.bikes!='undefined')
>             return "bikes:"+station.data.bikes ;
>         else if(typeof station.data.docks!='undefined')
>             return "docs:"+station.data.docks;
>     }  ,
>     yOffset : function(station){
>
>         // - for docks, + for bikes , how ?
>         if(typeof station.data.bikes!='undefined')
>             return 100;
>         else if(typeof station.data.docks!='undefined')
>             return 0;
>     },
>     grap : function(station){
>         // - for docks, + for bikes , how ?
>         if(typeof station.data.bikes!='undefined')
>             return
> '
> http://www.inflatable-watertoy.com/photo/pm818499-lovely_durable_pvc_inflatable_beach_balls_with_smiling_face_to_play_in_the_water_pool.jpg
> '
> ;
>         else if(typeof station.data.docks!='undefined')
>             return
> 'http://www.gettyicons.com/free-icons/123/onebit-3/png/48/sad_face_48.png
> ';
>     }
> }
>
> var style = new OpenLayers.Style({
>     pointRadius : 15,
>     fillColor: '#32cd32',
>     label: '${label}',
>     graphicYOffset: "${yOffset}",
>     externalGraphic: "${grap}"
> },{
>     context:{
>      label : function(station){
>         // docks or bikes , how ?
>         if(typeof station.data.bikes!='undefined')
>             return "bikes:"+station.data.bikes ;
>         else if(typeof station.data.docks!='undefined')
>             return "docs:"+station.data.docks;
>     }  ,
>     yOffset : function(station){
>
>         // - for docks, + for bikes , how ?
>         if(typeof station.data.bikes!='undefined')
>             return 100;
>         else if(typeof station.data.docks!='undefined')
>             return 0;
>     },
>     grap : function(station){
>         if(typeof station.data.bikes!='undefined')
>             return
> '
> http://www.inflatable-watertoy.com/photo/pm818499-lovely_durable_pvc_inflatable_beach_balls_with_smiling_face_to_play_in_the_water_pool.jpg
> '
> ;
>         else if(typeof station.data.docks!='undefined')
>             return
> 'http://www.gettyicons.com/free-icons/123/onebit-3/png/48/sad_face_48.png
> ';
>     }
>
>
>     }
> });
>
> var stationsLayer = new OpenLayers.Layer.Vector('Stations' , {styleMap :new
> OpenLayers.StyleMap(style)} );
> //stationsLayer.addFeatures(stations);
> stationsLayer.addFeatures(resultVectors);
> var map = new OpenLayers.Map({
>     div: "map",
>     center : [0,0],
>     zoom:2,
>     layers: [new OpenLayers.Layer.OSM(),stationsLayer ],
>     controls:[new OpenLayers.Control.Navigation(),new
> OpenLayers.Control.LayerSwitcher()]
> });
>
>
>
>
>
>
>
> --
> View this message in context:
> http://osgeo-org.1560.n6.nabble.com/Vector-layer-and-multiple-symbolizers-tp5032127p5032993.html
> Sent from the OpenLayers Users mailing list archive at Nabble.com.
> _______________________________________________
> Users mailing list
> Users at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/openlayers-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/openlayers-users/attachments/20130208/18c3337a/attachment-0001.html>


More information about the Users mailing list