[OpenLayers-Users] wfs stylemap example?

Eric Lemoine eric.c2c at gmail.com
Thu Jul 31 17:43:34 EDT 2008


Hi Alexandre.

So on hover you want to change the style of the feature but you dont
want to actually select the feature (and have the featureselected
event triggered). The actual feature selection occurs on click. This
is making sense to of :)

To get that behavior i would do the following: use a select feature
control with hover:false (the default) to select feature on click. For
changing feature style on hover, as hinted by Ivan, i would implement
a custom control based on the feature handler. That control would
register over and out callabals in the feature handler and do the
feature style change in these callbacks. That control would look like
the select feature control, but simpler. Hope this is making sense.

Eric

2008/7/30, Alexandre Dube <adube at mapgears.com>:
> Hi Arnd,
>
>     Thanks for very much for your tips.  That works just fine !
>
>     But for my little application it's not really useful.  Do you know a
> way to just change the color of a feature on "hover" without selecting
> it ?  That would be useful for me because I have lines as vector
> features and those are really hard to select by clicking on them.  You
> have to be really precise.
>
>     With a color change, that would be easier to know you can now click
> on it.  And I don't know if that's possible but it would be nice to have
> a bigger "pixel tolerance" when I click.  Any clues about that ?
>
> Arnd Wippermann wrote:
>> Hi Alexandre,
>>
>> i have also tried your example and get it working for me. Also for the
>> 'select' rule mentioned by Todd, but on the modifyFeature control instead
>> on
>> the selectFeature control. I don't know why. Thanks for the example
>> source.
>>
>> To select a feature with hover you can set 'hover' to true for the
>> selectFeature control. See below.
>>
>> It's the first time I tried the options for the selectFeature control in
>> an
>> own application. They work great. Only 'shiftKey' is a bit awksome,
>> because
>> if you don't hit the feature you zoom one level high.
>>
>> Arnd Wippermann
>>
>> part from select-feature.html:
>>
>> drawControls = {
>>     point: new OpenLayers.Control.DrawFeature(
>>         vectors, OpenLayers.Handler.Point
>>     ),
>>     line: new OpenLayers.Control.DrawFeature(
>>         vectors, OpenLayers.Handler.Path
>>     ),
>>     polygon: new OpenLayers.Control.DrawFeature(
>>         vectors, OpenLayers.Handler.Polygon
>>     ),
>>     select: new OpenLayers.Control.SelectFeature(
>>         vectors,
>>         {
>>             clickout: false, toggle: false,
>>             multiple: false, hover: false,
>>             toggleKey: "ctrlKey", // ctrl key removes from selection
>>             multipleKey: "shiftKey" // shift key adds to selection
>>         }
>>     )
>> };
>>
>> for(var key in drawControls) {
>>     map.addControl(drawControls[key]);
>> }
>>
>>
>> -----Ursprüngliche Nachricht-----
>> Von: users-bounces at openlayers.org [mailto:users-bounces at openlayers.org] Im
>> Auftrag von Alexandre Dube
>> Gesendet: Mittwoch, 30. Juli 2008 16:05
>> An: Brenningmeyer, Todd
>> Cc: Users at openlayers.org
>> Betreff: Re: [OpenLayers-Users] wfs stylemap example?
>>
>> Hi Todd,
>>
>>   You're right.  That would be the good way to set a color to a selected
>> feature.  But first I suggest you to pick an other color than blue because
>> it is the default color for "select".
>>
>>   Second, you actually have to select it, like with a selectFeature or
>> modifyFeature control.  By clicking on it, it will change your color.
>> See the example : http://openlayers.org/dev/examples/modify-feature.html
>>
>>   About the "hover" stuff, anybody correct me if I am wrong, but I would
>> try
>> to register an event with "mousemove" that would call the clickFeature
>> function in the selectFeature.js file ( or an other function that does the
>> same thing ).  Instead of having to click on the feature directly, being
>> over it would select it and change its color.
>>
>>   But, that would be annoying because if you would actually want to select
>> it ( and keep it selected ) you would not be able to because as soon as
>> your
>> mouse would not be over it, it would be unselected.
>>
>>   Hope this can be of any help,
>>
>> Brenningmeyer, Todd wrote:
>>
>>> Thanks so much!!! That's just what I was looking for.  My features are
>>> now
>>>
>> displaying as I'd hoped.  Is it difficult to extend this to change
>> features
>> that are selected onhover?  I added:
>>
>>> var selrules = [new OpenLayers.Rule({
>>> symbolizer: {strokeColor:"blue",strokeWidth: 2},
>>> elseFilter: true
>>> })];
>>> oStyleMap.styles["select"].addRules(selrules);
>>>
>>> to your .js file but nothing happens when I hover over the points
>>> (it's a bit gawdy but I just wanted to see if it would work).  I think
>>> I need to add a control but haven't tried this before.  Will this
>>> work?  The points aren't currently changing.  Are there additional
>>> considerations that I need to think about.  I'm just trying to port my
>>> old mapserver interface to openlayers and any help is appreciated.
>>> Thanks again, Todd
>>>
>>> -----Original Message-----
>>> From: Alexandre Dube [mailto:adube at mapgears.com]
>>> Sent: Tue 7/29/2008 3:22 PM
>>> To: Brenningmeyer, Todd
>>> Cc: Users at openlayers.org
>>> Subject: Re: [OpenLayers-Users] wfs stylemap example?
>>>
>>> Hi Todd,
>>>
>>> I have some to share. My WFS layer contains line features ( roads )
>>> and they have different color depending on their type ( Local road,
>>> Highway, etc ). I hope this can be of any help :
>>>
>>> ============= otherfile.js =============
>>>
>>> // prepare to style the data
>>> var oStyleMap = new OpenLayers.StyleMap();
>>>
>>> // Array of symbolizer and other values for ROL_CO_CLA attribute //
>>> this will be used to create a html select list and will be used // as
>>> the symbolizer array for the addUniqueValueRules function // sorry,
>>> there's some french words here :) var aRoadType = new Array();
>>> aRoadType = {
>>> AUT: {
>>> text: "Autoroute",
>>> strokeColor: "#ff0000", strokeWidth: 3 },
>>> NAT: {
>>> text: "Nationale",
>>> strokeColor:"#ff8c00", strokeWidth: 2 },
>>> REG: {
>>> text: "Régionale - Reg",
>>> strokeColor:"#ff8c00", strokeWidth: 2 },
>>> COL: {
>>> text: "Régionale - Col",
>>> strokeColor:"#ff8c00", strokeWidth: 2 },
>>> ACC: {
>>> text: "Locale - Acc",
>>> strokeColor:"#d2b48c", strokeWidth: 2 },
>>> LOC: {
>>> text: "Locale - Loc",
>>> strokeColor:"#d2b48c", strokeWidth: 2 },
>>> ACH: {
>>> text: "Chemin forestier - Ach",
>>> strokeColor:"#734c00", strokeWidth: 2 },
>>> MRN: {
>>> text:"Chemin forestier - Mrn",
>>> strokeColor:"#734c00", strokeWidth: 2 } }
>>>
>>> // a style will applies to each drawned vector feature depending on //
>>> the ROL_CO_CLA attribute value. It will match the good value and
>>> applies // the corresponding symbolizers
>>> oStyleMap.addUniqueValueRules("default", "ROL_CO_CLA", aRoadType);
>>>
>>> // If no rules applies to the current vector feature, that means it's
>>> // not a road, but an other type of feature like a circle for drag //
>>> control. The "elseFilter: true" is used to display those vectors.
>>> var rules = [new OpenLayers.Rule({
>>> symbolizer: {strokeColor:"#FF0000",strokeWidth: 2},
>>> elseFilter: true
>>> })];
>>> oStyleMap.styles["default"].addRules(rules);
>>>
>>> ============= yourHTMLFile.html =============
>>>
>>> --- inside your <head> section ---
>>> <script src="otherfile.js"></script>
>>>
>>> --- inside your init() function ---
>>>
>>> OpenLayers.Feature.Vector.style['default']['strokeWidth'] = '2';
>>>
>>> // then some variables... map definition... base layer ... some WMS
>>> layers ... and :
>>>
>>> olWFSRoads = new OpenLayers.Layer.WFS( "Roads - WFS", sMSURL, {
>>> typename: "roads", map: sMapPath }, { extractAttributes: true,
>>> minScale: 49999,
>>> typename: "roads", styleMap: oStyleMap } );
>>>
>>> // then addlayers, controls, etc. and your <body>
>>>
>>> Brenningmeyer, Todd wrote:
>>>
>>>
>>>> Hello,
>>>> Does anyone have an example code snippet that shows how to use a
>>>> stylemap
>>>>
>> with wfs data that is being served as vectors (I'm trying to serve up
>> points).  I've been trying to get this to work using some of the examples
>> on
>> the wiki but I can't quite get the syntax to work properly.  If anyone has
>> ideas or an example that would be great.
>>
>>>> Thanks,
>>>> Todd
>>>> _______________________________________________
>>>> Users mailing list
>>>> Users at openlayers.org
>>>> http://openlayers.org/mailman/listinfo/users
>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>> --
>> Alexandre Dubé
>> Mapgears
>> www.mapgears.com
>>
>> _______________________________________________
>> Users mailing list
>> Users at openlayers.org
>> http://openlayers.org/mailman/listinfo/users
>>
>>
>
>
> --
> Alexandre Dubé
> Mapgears
> www.mapgears.com
>
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users
>


More information about the Users mailing list