[OpenLayers-Dev] Live Tracking using Open Layers]

Erik Uzureau euzuro at gmail.com
Thu Oct 19 00:35:18 EDT 2006


Dear ngsuwei,

My first reaction is that removing and adding maxTrack markers every ten
seconds seems like not the best way to go about this.

Currently in the OL Marker library, there is no code to change a
marker's lonlat,
though perhaps there should be. I have added a ticket to trac
(http://trac.openlayers.org/ticket/358) with a suggested (though
untested) fix.

The idea then is that instead of storing the separate lon[] and lat[] arrays,
you would call markers.addMarker() *once* in your init function, and then
in your move() function, you would iterate through the markers.markers[]
array, calling setLonLat() to update each marker's position dynamically.

If you can get that suggested bit of code I put in the ticket to work, it would
be awesome if you could build that into a patch and attach it to the ticket...

See: http://trac.openlayers.org/wiki/CreatingPatches

Thanks, and hope that helps!

Erik

On 9/30/06, ngsuwei at stee.stengg.com <ngsuwei at stee.stengg.com> wrote:
> I am trying to simulate a web based so-called "live" tracking of resources
> on the map using OL. For this i am using markers. What i do was to
> retrieve the latest lat lon of the tracked resources thru ajax (at 10
> seconds interval) and then remove all the existing markers on the map and
> add new markers with the latest lat lon as to reflect the latest resources
> position.
>
> Before i tried using ajax. I had tried simulating the resources movement
> but adding and removing the markers on the map. After some time, i found
> that there was serious memory leaks problem.
>
> Can anyone advice me on what has gone wrong. Or are there any better
> resolution to achieve this?
>
> Following is the code that i use.
>
>   var zoom = 3;
>   var map, markers;
>   var latlon;
>   var lat = new Array();
>   var lon = new Array();
>   var forward = true;
>   var timerID;
>   var maxTrack = 100
>
>   function init(){
>     map = new OpenLayers.Map('map');
>     wms = new OpenLayers.Layer.WMS( "OpenLayers WMS",
>                 "http://labs.metacarta.com/wms/vmap0", {layers: 'basic'} );
>     map.addLayer(wms);
>
>     markers = new OpenLayers.Layer.Markers("markers");
>     map.addLayer(markers);
>     map.setCenter(new OpenLayers.LonLat(5, 40), zoom);
>     map.addControl( new OpenLayers.Control.LayerSwitcher() );
>
>     var i = 0;
>     lon[0] = 3;
>     lat[0] = -40;
>     for (i=1;i<maxTrack;i++){
>       lon[i] = lon[i-1] + 3;
>       lat[i] = lat[i-1] + 3;
>
>     }
>
>     timerID = window.setInterval('move()',2000);
>   }
>
>   function move(){
>     var i = 0;
>     markers.clearMarkers();
>     for (i=0;i<maxTrack;i++){
>         add(i);
>     }
>   }
>
>   function add(i) {
>     markers.addMarker(new OpenLayers.Marker(getLonLat(i), null));
>   }
>
>   function getLonLat(i){
>     if (lat[i] >= 80 && lon[i] >= 10){
>       forward = false;
>     }else if (lat[i] <= 40 && lon[i] <= 3){
>       forward = true;
>     }
>     if (forward == false){
>       lat[i] = lat[i] - 2;
>       lon[i] = lon[i] - 1;
>     }else{
>       lat[i] = lat[i] + 2;
>       lon[i] = lon[i] + 1;
>     }
>     return new OpenLayers.LonLat(lon[i],lat[i]);
>   }
>
>   function doUnload(){
>     if(timerID) {
>       clearTimeout(timerID);
>       timerID  = 0;
>      }
>   }
>
>
>
> [This e-mail is confidential and may be priviledged. If you are not the
> intended recipient, please kindly notify us immediately and delete the
> message
> from your system; please do not copy or use it for any purpose, nor disclose
> its contents to any other person. Thank you.]
> ---ST Electronics Group---
>
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users
>
> _______________________________________________
> Dev mailing list
> Dev at openlayers.org
> http://openlayers.org/mailman/listinfo/dev
>



More information about the Dev mailing list