[GIS] Is there OpenLayers layer type that supports just labels

annotation;openlayers-2

Is there an OpenLayers layer type that supports just labels on a map without an underlying feature?

I think this is called an annotations layer in GIS.

If not, I'm not sure how to approach this and any advice would be appreciated. I thought styling a vector point layer so that the point itself would be invisible might be a good approach but then the user won't be able to select/edit/delete the feature, which is part of the requirement.

The application is a bit like the 'Create Map' functionality in Google Maps. The user can add markers, lines and polygons to the map using OpenLayers vector editing controls. A popup allows them to edit a label, change the styling and delete the feature. The map settings (zoom, centre, background layer) and features are saved to a SQL Server database and stored as geometry. This is sent to the database as WKT but the layers are loaded as GeoJSON from a handler on the website.

The client has asked for the ability for users to just place labels on the map (without a marker) and save these too. As I mentioned above, I thought about implementing this as a labelled point layer with the points styled to be invisible but this stops the user from selecting/editing existing features.

My question was whether there was an annotation layer type where the user can create annotations, select them and move them around on the map – similar to vector layers.

It looks like there isn't so how should I go about approaching this?

Best Answer

It depends of what you have on the server side.

In case you use MapServer, you can create layer of TYPE annotation that will show only features names. From MapServer's documentation:

TYPE [annotation|chart|circle|line|point|polygon|raster|query] Specifies how the data should be drawn. Need not be the same as the shapefile type. For example, a polygon shapefile may be drawn as a point layer, but a point shapefile may not be drawn as a polygon layer. Common sense rules. Annotation means that a label point will be calculated for the features, but the feature itself will not be drawn although a marker symbol can be optionally drawn. this allows for advanced labeling like numbered highway shields. Points are labeled at that point. Polygons are labeled first using a centroid, and if that doesn’t fall in the polygon a scanline approach is used to guarantee the label falls within the feature. Lines are labeled at the middle of the longest arc in the visible portion of the line. Query only means the layer can be queried but not drawn (http://goo.gl/Y3HqU).

Then, the client - OpenLayers, for instance - can get this layer via WMS.

In case you use GeoServer a similar solution can be gotten by creating an style - using SLD - that will tell the server to render just the labels, and not the features. Once this style has been created, all the client has to do is requesting the WMS layer with a GetMap request with the parameter styles set to the one created for this task. In my personal blog there is a post with a detailed example that uses this approach (http://goo.gl/pKDhZ).