[OpenLayers-Dev] Problems trying to move a Feature (Marker)

XinGang Li slinavlee at gmail.com
Fri Apr 2 01:22:18 EDT 2010


After changed the geometry of the feature, you should redraw the feature.

Li XinGang
EMail: slinavlee at gmail.com
Blog:   avlee.cnblogs.com
Site:    www.mapboost.org


On Fri, Apr 2, 2010 at 6:43 AM, Cúmar Cueva <qmarqeva at gmail.com> wrote:

> Hi guys,
>
> Please I need your help. I want to move a Marker (that was colocate using a
> VectorLayer, that works ok), but I can't do that, yet... Here is the code:
>
> For create the Map:
>
> //Map
> map = new OpenLayers.Map("map", {
>                controls:[
>                    new OpenLayers.Control.Navigation(),
> new OpenLayers.Control.MousePosition(),
>                    new OpenLayers.Control.Attribution(),
>                    new OpenLayers.Control.Permalink(),
>                    new OpenLayers.Control.PanZoomBar(),
> new OpenLayers.Control.KeyboardDefaults(),
> new OpenLayers.Control.LayerSwitcher()
>                    ],
>                maxExtent: new
> OpenLayers.Bounds(-79.23381,-3.96749,-79.17630,-4.00457),
>                displayProjection: new OpenLayers.Projection("EPSG:4326"),
> projection: new OpenLayers.Projection("EPSG:900913"),
>                units: 'm',
>
>                numZoomLevels: 19,
>                maxResolution: 'auto'
>            } );
>  map.addLayer(new OpenLayers.Layer.OSM.Mapnik("Mapnik"));
>
> And a function for move:
>
>
>  function moveFeatures(vectorLayer1){
>
> var features = vectorLayer1.features, selectedPlane = null;
>   for (var i=features.length-1;i>=0;i--) {
>   var feature = features[i];
>   var poppedup = feature.attributes.poppedup;
>   var x = feature.geometry.x + Math.cos(15 * Math.PI / 180) / 5;
>   var y = feature.geometry.y + Math.sin(15 * Math.PI / 180) / 5;
>
> if (poppedup == true) {
>   selectControl.unselect(feature);
>   }
>
>   if (vectorLayer.map.getExtent().contains(x, y)) {
>
> var newPoint = new OpenLayers.LonLat(x, y);
> feature.move(newPoint);
>  if (poppedup == true) {
>   selectControl.select(feature);
>   }
>   }
>   else {
>   vectorLayer.destroyFeatures([feature]);
> feature.destroy();
> feature = null;
>   }
>   }
> //only for simulate moved
>   setTimeout(function(){moveFeatures(vectorLayer, vectorLayer.features ||
> [])}, 1000);
>   }
>
> I put some "alerts" in javascript for view lat and lon values, and  these
> change correctly... but the Marker in the map don't move !!!! please help
> me....
>
>
> --
> Atte,
>
> Cúmar Cueva
> _______________________________________________
> Dev mailing list
> Dev at openlayers.org
> http://openlayers.org/mailman/listinfo/dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-dev/attachments/20100402/6a4c79ef/attachment.html


More information about the Dev mailing list