[OpenLayers-Users] marker using a on-the-fly created icon

Donald Kerr donald.kerr at dkerr.co.uk
Sun Apr 22 04:25:49 EDT 2012


... and, if your vector layer comes from a WFS, and assuming the vehicle
plate is one of the feature attributes, you can create a label with that
information:

style.label: "${getLabel}",
style.labelAlign: "lt",
style.labelXOffset: "-16",
style.labelYOffset: "-20",
style.fontColor: "black",
style.fontSize: "12",
style.fontFamily: "'Arial'",
style.fontWeight: "bold",
style.labelOutlineColor: "#FFFFC0",
style.labelOutlineWidth: 4

And in "Context":

getLabel: function(feature) {
  return feature.attributes['VehiclePlate'];
}


Regards,

Donald



-----Original Message-----
From: openlayers-users-bounces at lists.osgeo.org
[mailto:openlayers-users-bounces at lists.osgeo.org] On Behalf Of Steve Nelson
Sent: 22 April 2012 05:07
To: alexe100
Cc: openlayers-users at lists.osgeo.org
Subject: Re: [OpenLayers-Users] marker using a on-the-fly created icon


Sure this can be done. Use vectors, not markers. Markers are deprecated and
will drive you nuts with bugs.


With vectors you create a "style" and set the externalGraphic to the URL of
the image you want. Something like this (this is totally untested, so mess
around with it):


style = OpenLayers.Util.extend({},
OpenLayers.Feature.Vector.style['default']);
style.externalGraphic="http://domain.com/yourimage.png"
style.graphicWidth=62
style.graphicHeight=38


vectorPoint=new OpenLayers.Geometry.Point(-76.269, 36.8741);


vector = new OpenLayers.Feature.Vector(vectorPoint,null,style);


vectorLayer.addFeatures([vector]);




Anyway, that's the vector part, the canvas part may be a little trickier,
because you need to ultimately create a URL.


Maybe what you could do is base64 the canvas image, then use that as your
url. Or if you use html5 file writer, you could write it locally in the
browser. You've probably already seen this, but you can base64 the image and
use it like a url, like this:


<img src="data:image/png;base64,iVBORw0KGgoAAAANSiVBORw0KGgoAAAANS">


Did that help?


Steve


On Sat, Apr 21, 2012 at 11:28 PM, alexe100 <imoveisnacionais at gmail.com>
wrote:

Hi
I would like to set an icon to a marker with specific information, for
example the veicle plate and not the same icon for all the markers.

Is it possible to create an icon on the fly using a canvas or something and
set that icon or image to a specific marker?

Like this: imagine a map with 10 markers (veicles). All the markers are
resoresented by the same global image/icon but bellow the icon or image
there is allways present the veicle plate.



Thanks a lot


Alex

--
View this message in context:
http://osgeo-org.1560.n6.nabble.com/marker-using-a-on-the-fly-created-icon-t
p4906613p4906613.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.
_______________________________________________
Users mailing list
Users at lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/openlayers-users



More information about the Users mailing list