Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Yesterday I was trying to create first mock-ups of my GPS tracker interface, and was exploring the available OpenLayers objects for drawing on a map.

I began with simple task - placing a marker on a map, on a Markers layer. I added the appropriate image to the marker, learned how to move it on a map, and added a Popup to the onclick event that opens additional info about that marker. Works great. Since I wanted this marker to represent the vehicle, the next step was going to be to populate the content of the marker's Popup using AJAX. When the onclick event occurs I'll send the marker's ID to my python script, fetch the latest data from my postGIS database and update the marker and it's popup appropriately.

But then I saw in the OpenLayers documentation that markers don't have ID attribute, and that I'll probably have to end up using vector or feature object. OK, both of them have id attribute and createMarker methods, so I'll easily transfer my Markers into Features/Vectors. After that I saw an example on the web where someone just initializes id attribute to the marker like this:

marker = new OpenLayers.Marker(new OpenLayers.LonLat(90,10),icon.clone());
marker.id = 353;

And it works fine, I can now add various attributes to my markers and use the as needed. For example:

marker.id = 353;
marker.popups_id = 382;
marker.data = "Marker for a vehicle";

So, after I've done what I wanted in the start I started wondering - what are the main reasons for these 3 different Classes if I can take Marker and fill it with various data to make it look like a feature. Am I doing it wrong, is there a better approach? It seems to me that I could create my map objects using Markers only, but I don't want to regret that later if I hit it's limits. Are there any size/performance limits and recommendations when to use Markers and when Features or is it all based on testing and refactoring as needed?

Just to add, my application will be a simple GPS tracker. So I'll be using OpenLayers to display objects, move them, animate them, show their properties and similar tasks. I'll have to support having minimal 300 active objects on a map in the same moment, and refresh their coordinates at least every 15seconds.

TIA for all your advices that could possibly lead me in the right direction of creating the effective interface for my application.

share|improve this question

1 Answer 1

up vote 7 down vote accepted

I would personally go with features over markers. Point features (and all features) allow for labeling and can be represented in different shapes and colors like circles, x, square and so forth. Not to mention all the additional intrinsic functionality and flexibility features have over markers such as geographical calculations, transformations, click/highlight/select handlers and on and on.

enter image description here

I hate to be pushy, but it would be beneficial if you used something like GeoServer or MapServer on the back end. You could set a WFS strategy that works on your 5-30 second (or whatever) interval timer and allow it to fetch and render the features automatically. In case you're wondering, it already does this in ajax form. So you don't have to write the code to query the database, parse, convert, etc... on 300 objects on your map. Openlayers will render the latest WFS data on your Geoserver which is pointed to PostGIS. You would save yourself a lot of time and effort reinventing that wheel. Openlayers WFS protocol can be set to query based on your viewport on a temporal filter.

Though features don't perform well when there are a lot of them. 300 might be pushing it. If you see that performance is an issue, you can easily switch to using WMS (only if you have Geoserver or Mapserver). You can also use a cluster strategy to minimize un necessary features on your map.

share|improve this answer
    
Thanks for your extremely informative and constructive comments. –  D00de Feb 18 '12 at 14:51

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.