[OpenLayers-Users] Reload marker

Eric Lemoine eric.c2c at gmail.com
Thu Aug 21 12:06:46 EDT 2008


Hi.

I may be indeed wise to detach a marker from its feature before
destroying it. One other solution - although not sure it applies to
your case - would be to destroy the feature, i can't easily check
right now but i'm pretty sure destroying a feature destroys its
internal marker.

Now, whether i like it: no :-) just kidding. In fact i'm wondering
whether you could use the "new way" and display your markers in a
vector layer (using the externalGraphic style property to reference
your marker pictos). In particular this would make your code clearer
because i'll manipulate features only, not features and markers. You
way also want to use Layer.GML to push as much code as possible out of
your application.

I have a doubt. Chris, Andreas, are there still limitations with using
Vector+externalGraphics over using regular markers? Chris, i remember
you told me there was, but this was a long time ago and i can't recall
what it was.

Eric

2008/8/21, Walter Lorenzetti <lorenzetti at gis3w.it>:
> Walter Lorenzetti ha scritto:
> I think I found the solution, befor removeMarker() from layer markers
> and after I destroy the marker:
>
> function destroy_punti(){
>   for (var tp in legDbTipo){
>     for(var m in punti[tp].markers){
>       var mtd = punti[tp].markers[m];
>       punti[tp].removeMarker(mtd)
>       mtd.destroy();
>     }
>   }
> }
>
> Could be correct, like method?
>
> W
>> Hi list,
>>
>> I've a problem with a reloading of several markers layers
>>
>> On my application I've n markers layer where I add severla
>> OpenLayers.Marker by parsing a featureserver gml output (I hope you
>> understand...)
>>
>> like this:
>>
>> for (var tp in legDbTipo){
>>   punti[tp] = new OpenLayers.Layer.Markers(tp);
>> }
>>
>>
>>
>> function parseData(req) {
>>           g =  new OpenLayers.Format.GML();
>>           features = g.read(req.responseText);
>>           for(var feat in features) {
>>             // si crea la feature
>>
>>             var f = new OpenLayers.Feature(base, new
>> OpenLayers.LonLat(features[feat].geometry.x,features[feat].geometry.y));
>>               f.attributes = new Object;
>>               for (var j in features[feat].attributes) {
>>                   f.data[j] = features[feat].attributes[j];
>>                   f.attributes[j] = features[feat].attributes[j];
>>               }
>>               f.closeBox = true;
>>               f.popupClass = AutoSizeFramedCloudMinSize;
>>               f.data.popupContentHTML = bulidFormpopup(f,true);
>>               f.data.overflow = "auto"
>>               var size = new
>> OpenLayers.Size(legDbTipo[f.data.tipo].dimLegMapIcon.w,legDbTipo[f.data.tipo].dimLegMapIcon.h);
>>               f.data.icon = new
>> OpenLayers.Icon(legDbTipo[f.data.tipo].urlLegMapIcon,size);
>>               OpenLayers.Console.log(f);
>>             // si crea il marker
>>             var m = f.createMarker();
>>
>>             m.events.register("mousedown", f, markerClick);
>>
>>             var markerClick = function (evt) {
>>                 if (this.popup == null) {
>>                     this.popup = this.createPopup(this.closeBox);
>>                     map.addPopup(this.popup);
>>                     this.popup.show();
>>                 } else {
>>                     this.popup.toggle();
>>                 }
>>                 currentPopup = this.popup;
>>                 OpenLayers.Event.stop(evt);
>>             };
>>             punti[f.data.tipo].addMarker(m);
>>           }
>>         }
>>
>>
>> function load_punti(){
>>   OpenLayers.loadURL("/fs/featureserver.cgi/punti_turistici?format=GML",
>> "", null, parseData);
>> }
>>
>> If I want to refresh my data I write this function:
>>
>> function destroy_punti(){
>>   for (var tp in legDbTipo){
>>     for(var m in punti[tp].markers){
>>       punti[tp].markers[m].destroy();
>>     }
>>   }
>> }
>>
>> so with this I destroy every markers before created....
>>
>> and after running load_punti() again I repopulate my markers layers...
>>
>> but after that I've a problem with every action on the map because on
>> firebug I obtain the segunt error:
>>
>> this.events is null
>> this.events=new
>> OpenLayers.Events(this,t...this.icon!=null)){this.icon.moveTo(px);}
>>
>> Someone have an idea about this error?
>>
>> Thanks in advance
>>
>> Walter
>>
>> _______________________________________________
>> Users mailing list
>> Users at openlayers.org
>> http://openlayers.org/mailman/listinfo/users
>>
>
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users
>



More information about the Users mailing list