[OpenLayers-Dev] adding markers with popups as features.

Eric Lemoine eric.c2c at gmail.com
Fri Aug 22 14:00:55 EDT 2008


As I said you use OpenLayers.Layer.Vector so you don't use
OpenLayers.Feature but OpenLayers.Feature.Vector, which has a move()
method, at least in trunk. Eric

2008/8/22, Fred Arters <fred at monkeytroy.com>:
> Hey Eric, I know I had a lot in that last email.. but the first part
> is...
>
>>> According to the documentation and looking at the source the class
>>> Feature does not have a move method.
>
> This seems to be the case for the stable 2.5 release which I am using
> and the trunk..
>
> Here is a link to the Feature.js on trunk.  I can't find a move method.
>
> http://trac.openlayers.org/browser/trunk/openlayers/lib/OpenLayers/Feature.js
>
> Documentation for trunk does not show a move method either.
>
> Am I looking in the wrong spot?
>
>
> On Aug 22, 2008, at 12:15 PM, Eric Lemoine wrote:
>
>> Hi. If you use Vector.Layer then your feature class should be
>> Feature.Vector, which further means you should be able to do
>> feature.move(). IIRC move takes either an OpenLayers.Pixel or an
>> OpenLayers.LonLat as an argument. My comments apply to current trunk,
>> you may want to check that they apply to the version of OL you're
>> using. Cheers. Eric
>>
>> 2008/8/22, Fred Arters <fred at monkeytroy.com>:
>>> Hey Eric,
>>>
>>> I looked into this a bit yesterday.. here is what I found.
>>>
>>> According to the documentation and looking at the source the class
>>> Feature does not have a move method.
>>>
>>> According to the documentation, the class Vector *does* have a move
>>> method.   However, if you attempt to call move on a vector object, it
>>> throws a javascript error saying the object has no move method.
>>> Looking at the source confirms that there is no move method.
>>>
>>> The Vector's geometry attribute is a Point which has a move
>>> method.  I
>>> tried that and it did redraw the point but it draws it using relative
>>> pixels for the x, y values.   So move (5, 5) does not move it to lon:
>>> 5, lat: 5 but it moves it 5px up and 5px to the right.
>>>
>>> Looking at the source for the move method on the Point class I
>>> noticed
>>> move function does this.x = this.x + x.   Then it calls
>>> clearBounds().
>>>
>>> So I did this...
>>>
>>> function myMove(pID, pLon, pLat) {
>>>
>>>     var v = vectorLayer.getFeatureById(pID);
>>>
>>>     v.geometry.x = pLon;
>>>     v.geometry.y = pLat;
>>>     v.geometry.clearBounds();
>>>     v.layer.drawFeature(v);
>>> }
>>>
>>> And that worked.   Though it feels like a hack.  Seems like there
>>> should be a move method to do this in addition to the move method to
>>> move a Point in relative pixels.
>>>
>>> How would I suggest such a change or did I miss a more correct way to
>>> do this?
>>>
>>> Thanks for you help on this btw.
>>>
>>> -Fred
>>>
>>>
>>> On Aug 22, 2008, at 3:35 AM, Eric Lemoine wrote:
>>>
>>>> On Thu, Aug 21, 2008 at 11:51 PM, Fred Arters <fred at monkeytroy.com>
>>>> wrote:
>>>>> Thanks for the advice.  I have it working now using Vector with an
>>>>> externalSymbol style as you suggest.   Seems to work fine and a bit
>>>>> cleaner
>>>>> as I don't have to add a separate pop up and marker for each
>>>>> feature.
>>>>> Thanks.
>>>>>
>>>>> Though I do have a question... what would be the correct way to
>>>>> then move
>>>>> one of my marker as a vector?   For a feature all I had to do was
>>>>> set the
>>>>> lonlat attribute and refresh the layer and it moved..  but that
>>>>> doesn't seem
>>>>> to work with a Vector.  The documentation says there is a move
>>>>> function but
>>>>> it fails and looking at the code does not seem to be there.
>>>>
>>>> Doing feature.move(px) or feature.move(lonlat) should work. Both the
>>>> Feature.Vector and Geometry.Point classes include move methods. If
>>>> that doesn't work, please come back with a simple example.
>>>>
>>>>
>>>>>
>>>>> I didn't see it but is there an example that does this too?
>>>>
>>>> No that I'm aware.
>>>>
>>>> Thanks,
>>>>
>>>> --
>>>> Eric
>>>
>>>
>
>



More information about the Dev mailing list