[OpenLayers-Dev] adding markers with popups as features.
Fred Arters
fred at monkeytroy.com
Fri Aug 22 11:00:40 EDT 2008
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