[OpenLayers-Users] Change position of vector marker

Mehmet Sirin m.sirin07 at googlemail.com
Mon Nov 16 13:26:24 EST 2009


Hi, anybody knows how to change the position of a vector marker?

lemme give you some pieces of the code  ( got it from
http://pgrouting.postlbs.org/wiki/WorkshopOL2.7andOSM "Getting the
OpenLayers-Code for the
Routing-application<http://pgrouting.postlbs.org/wiki/GettingtheOpenLayers-Code>
")



1.)        var SinglePoint = OpenLayers.Class.create();
        SinglePoint.prototype =
OpenLayers.Class.inherit(OpenLayers.Handler.Point, {
            createFeature: function(evt) {

 this.control.layer.removeFeatures(this.control.layer.features);
                OpenLayers.Handler.Point.prototype.createFeature.apply(this,
arguments);
            }
        });

        var start_style = OpenLayers.Util.applyDefaults({
            externalGraphic: "start.png",
            graphicWidth: 18,
            graphicHeight: 26,
            graphicYOffset: -26,
            graphicOpacity: 1
        }, OpenLayers.Feature.Vector.style['default']);

        var stop_style = OpenLayers.Util.applyDefaults({
            externalGraphic: "stop.png",
            graphicWidth: 18,
            graphicHeight: 26,
            graphicYOffset: -26,
            graphicOpacity: 1
        }, OpenLayers.Feature.Vector.style['default']);



2.)
init (){
...

                    start = new OpenLayers.Layer.Vector("Start point",
{style: start_style});
                    stop = new OpenLayers.Layer.Vector("End point", {style:
stop_style});

                    result = new OpenLayers.Layer.Vector("Routing results",
                                                 {style: result_style});

                    map.addLayers([mapnik, start, stop,result]);


                    // controls
                    controls = {
                             start: new
OpenLayers.Control.DrawFeature(start, SinglePoint),
                              stop: new OpenLayers.Control.DrawFeature(stop,
SinglePoint)
                    }
                    for (var key in controls) {
                        map.addControl(controls[key]);
                    }
        }


        function toggleControl(element) {
                    for (key in controls) {
                        if (element.value == key && element.checked) {
                                    controls[key].activate();
                        } else {
                                    controls[key].deactivate();
                        }
                    }

...

}





3.)

        function compute() {
...



                     startPoint = start.features[0];
                     stopPoint = stop.features[0];

Now I want to change the coordinates of the marker:


startPoint.geometry.x=x_pos;   //x_pos and y_pos are  dynamically taken
values out of the database.
startPoint.geometry.y=y_pos;

but it only works for some few zoom levels. When zooming in suddenly the
marker disappears  !

Why is that happening?


thank you
leaves you kind regards:
 mehmet sirin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20091116/ca31ac08/attachment.html


More information about the Users mailing list