[OpenLayers-Dev] Markers and Vector Layer conflict
Alex G.
unseen.wizard at gmail.com
Mon Feb 8 03:39:39 EST 2010
Alexandre,
thanks again for your help.
The event is not triggered with the code you posted so I changed a few
things around, though it's probably not the best way to do this, and it
seems to be triggered:
var oDrawPoint = new OpenLayers.Control.DrawFeature(vectors,
OpenLayers.Handler.Point);
vectors.events.on({'
featureadded': onPointFeatureAdded, 'scope': oDrawPoint });
function onPointFeatureAdded (event) {
var feature = event.feature;
if (feature.geometry.CLASS_NAME ==
'OpenLayers.Geometry.Point') {
var symbolizer =
feature.layer.styleMap.createSymbolizer(feature);
feature.style = symbolizer;
feature.style.externalGraphic =
\"images/markers/marker-gold.png\";
feature.style.pointRadius = 13;
feature.style.fillOpacity = 1;
feature.layer.drawFeature(feature);
}
}
Though that if statement there must be surely incorrect but I wasn't able to
trigger the event of a point added any other way.
On to figuring out the different images now!
Thanks,
Alex
On Fri, Feb 5, 2010 at 3:34 PM, Alexandre Dube <adube at mapgears.com> wrote:
> Alex,
>
> Instead of defining the externalGraphic property directly in your StyleMap
> (that affects all your features on your layer), you could register a
> "featureadded" event to your DrawFeature control for points and set the
> externalGraphic property there. You would need to redraw your feature to
> affect the new style. This might look like (untested) :
>
> var oDrawPoint = new OpenLayers.Control.DrawFeature(vectors,
> OpenLayers.Handler.Point);
> oDrawPoint.events.on({"featureadded": onPointFeatureAdded, scope:
> oDrawPoint});
>
> var onPointFeatureAdded = function(event) {
> var feature = event.feature;
> var symbolizer = this.layer.styleMap.createSymbolizer(feature);
> feature.style = symbolizer;
> feature.style.externalGraphic = "images/markers/marker-gold.png";
> feature.style.pointRadius = 10;
> this.layer.drawFeature(feature);
> };
>
> The remaining thing to do is to think about how to have different markers
> for your features.
>
> Hope this helps,
>
> Alexandre
>
>
>
> Alex G. wrote:
>
>> Alexandre,
>>
>> thanks again for your valuable help!
>>
>> At the moment the best idea would be to have vector points as markers,
>> which would make them both clickable and perfect for what I need to do.
>>
>> I have added this info to the vector layer:
>>
>> vectors = new OpenLayers.Layer.Vector('Vectors', {
>> styleMap: new OpenLayers.StyleMap({
>> externalGraphic: "images/markers/marker-gold.png",
>> pointRadius: 10
>> })
>> });
>>
>> And the point appears correctly with the marker icon. But I have run into
>> 2 problems now:
>>
>> 1) All my polygons and lines appear black or invisible
>> 2) I would like to use more than one image for the markers
>>
>> My controls looks like this:
>>
>> controls = {
>> point: new OpenLayers.Control.DrawFeature(vectors,
>> OpenLayers.Handler.Point),
>> line: new OpenLayers.Control.DrawFeature(vectors,
>> OpenLayers.Handler.Path),
>> polygon: new OpenLayers.Control.DrawFeature(vectors,
>> OpenLayers.Handler.Polygon),
>> drag: new OpenLayers.Control.DragFeature(vectors),
>> select: selectControl
>> };
>>
>> Is there a way to maybe pass the external image specifically to the
>> "point" control?
>>
>> I am unsure about the syntax and I wasn't able to find any info around,
>> maybe something like this:
>>
>> point: new OpenLayers.Control.DrawFeature(vectors,
>> OpenLayers.Handler.Point, {style: blah blah}),
>>
>> If it's possible, then that solves my 2nd problem as well for different
>> images.
>>
>> Thanks in advance!
>>
>> Best regards,
>>
>> Alex
>>
>>
>
> --
> Alexandre Dubé
> Mapgears
> www.mapgears.com
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-dev/attachments/20100208/a772826d/attachment.html
More information about the Dev
mailing list