[OpenLayers-Users] Layer.Vector with multiple data sources

Andreas Hocevar ahocevar at opengeo.org
Fri Jan 9 04:35:38 EST 2009


Hey Arnd-

Arnd Wippermann wrote:
> If you have found a solution, I would be interested. I have thought about a
> solution with all features on one vectorlayer and an attribute "group". I'm
> able to set the style of the features due to the zoomlevel, but I have no
> clue to hide features.
>   

See my proposals for a template and context which helps you do that below:

> // create the layer styleMap by giving the default style a context
> var colors = ["#FF0000", "#FF8000", "#FFFF00", "#80FF00", "#00FF00"];
> var context = {
>     getColor: function(feature) {
>         var region = parseInt(feature.attributes['group']);
>         if(map.getZoom()>5)
>             return colors[region];
>         return colors[map.getZoom()];
>     }
>   
      getVisibility: function(feature) {
          var visible = feature.attributes["group"] == visibleGroup;
          return visible ? "" : "none";
      }
> };
> var template = {
>     fillColor: "${getColor}", // using context.getColor(feature)
>   
      display: "${getVisibility}",
>     strokeColor: "#FF0000",
>     strokeWidth:3
> };
> map.layers[map.aktLayer].styleMap = new OpenLayers.Style(template, {context:
> context});
> map.layers[map.aktLayer].redraw();
>
> Perhaps Andreas you could gave a hint. In a previous post you have mentioned
> display:"none" to hide features, but i don't know where to use it.
>
> Especially can I use display:"none" with context and template?
>   

The above code snippet should answer your questions. It assumes that you
have a global variable visibleGroup which contains the name of the group
you want to show. If the value of this variable changes, you have to
redraw the layer.

Regards,
Andreas.

> Arnd Wippermann
>
>
>
>
>
>
>  
>
> -----Ursprüngliche Nachricht-----
> Von: users-bounces at openlayers.org [mailto:users-bounces at openlayers.org] Im
> Auftrag von Andreas Hocevar
> Gesendet: Samstag, 3. Januar 2009 17:30
> An: Heidt, Christopher M.
> Cc: users at openlayers.org
> Betreff: Re: [OpenLayers-Users] Hide features
>
> Hi,
>
> On Wed, Dec 3, 2008 at 10:05 PM, Heidt, Christopher M.
> <CHRISTOPHER.M.HEIDT at saic.com> wrote:
>   
>> How do I hide features?
>> I did it by changing my opacity to 0,
>> but I need to find another way because my features can have multiple 
>> styles, and I need the feature to retain whatever style it has when 
>> hidden and reshown.
>>     
>
> You just need to set the symbolizer (style) property "display" to "none"
> (like in CSS).
>
> So instead of
> var symbolizer = {
>     opacity: 0
> }
>
> you set
>
> var symbolizer = {
>     ...
>     display: "none",
>     ...
> }
>
> No other symbolizer properties will be lost (but the same is true for your
> opacity hack), and the feature will not be rendered until you delete the
> display property (or set it to a value other than "none").
>
> Regards,
> Andreas.
>
>
> --
> Andreas Hocevar
> OpenGeo - http://opengeo.org/
> Expert service straight from the developers.
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users 
>
> -----Ursprüngliche Nachricht-----
> Von: users-bounces at openlayers.org [mailto:users-bounces at openlayers.org] Im
> Auftrag von Alexandre Dube
> Gesendet: Donnerstag, 8. Januar 2009 19:38
> An: Andreas Hocevar
> Cc: OpenLayers users mailing list
> Betreff: Re: [OpenLayers-Users] Layer.Vector with multiple data sources
>
> Andreas Hocevar wrote:
>   
>> On Thu, Jan 8, 2009 at 6:42 PM, Alexandre Dube <adube at mapgears.com> wrote:
>>   
>>     
>>> Andreas Hocevar wrote:
>>>     
>>>       
>>>> Alexandre Dube wrote:
>>>> It should be easy to customize the strategy you are using (I assume 
>>>> Fixed or BBOX) to change the url and/or params of the protocol on 
>>>> the zoomend event (similar to the moveend event handler in the BBOX 
>>>> strategy). This strategy would then have to know the urls/params for 
>>>> each zoom level, and you would just interact with one vector layer.
>>>>
>>>>       
>>>>         
>>> Exactly.  It's a common practice on the web to have data normalized 
>>> by scales, so it would be quite useful to have such an upgrade.
>>>
>>> So, you would modify both BBOX and Fixed ?  Do others have opinions 
>>> about it ?
>>>     
>>>       
>> No, I'd encourage you to do this on the application level because it 
>> is less than 10 lines of code. If this is to become part of 
>> OpenLayers, it should be a separate strategy (a layer can have 
>> multiple strategies).
>>
>> Regards,
>> Andreas.
>>
>>   
>>     
>
> Understood.  I'll try to write a new strategy then.  Thanks a lot for the
> tips.
>
> --
> Alexandre Dubé
> Mapgears
> www.mapgears.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