[OpenLayers-Users] Reload marker

Walter Lorenzetti lorenzetti at gis3w.it
Thu Aug 21 10:59:12 EDT 2008


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
>   




More information about the Users mailing list