[OpenLayers-Users] Problems with WFS marker override object

David Martinez Morata damarmo at gmail.com
Fri Jun 20 09:13:14 EDT 2008


Hi List!

I'm new in OpenLayers and JavaScript :S!

I'm creating a web aplication with OpenLayers and I have two problems.

1. Why my html page don't work in InternetExplorer 6 ?

2. I need to show a pop up window with elemnts of a wfs layer and I try to
override the featureClass:OpenLayers.Feature.WFS
with the code I found in the UsersList but that nots works for me.
I show a vector points in my window, but the points are not static, if I pam
or zoom in the map the points change the position.

This is my code of the Script: and any sugestion are wellcome!


        // make map available for easy debugging
        var map;

        // avoid pink tiles
        OpenLayers.IMAGE_RELOAD_ATTEMPTS = 3;
        OpenLayers.Util.onImageLoadErrorColor = "transparent";


        function init(){
            var options = {numZoomLevels: 20,
               projection: new OpenLayers.Projection("EPSG:900913"),
               displayProjection: new OpenLayers.Projection("EPSG:4326")
              };
              // Create a map Object
            map = new OpenLayers.Map('map', options);

            // Create Google Mercator layers
            var gmap = new OpenLayers.Layer.Google(
                "Google Streets" // the default
            );
            var gsat = new OpenLayers.Layer.Google(
                "Google Satellite",
                {type: G_SATELLITE_MAP}
            );
            var ghyb = new OpenLayers.Layer.Google(
                "Google Hybrid",
                {type: G_HYBRID_MAP}
            );
            var gphy = new OpenLayers.Layer.Google(
                "Google Physical",
                {type: G_PHYSICAL_MAP}
            );

//                Create a WFS Sites Layer
                    var sites = new OpenLayers.Layer.WFS( "Sites",
               "
http://10.192.160.133/cgi-bin/mapserv.exe?map=/ms4w/apps/Test/WFS_Test.map",
               {typename: "Sites",maxfeatures: 100 },{
               featureClass: OpenLayers.Feature.WFS });

          var sitesconsul = new OpenLayers.Layer.WFS( "Consulte des Sites",
               "
http://10.192.160.133/cgi-bin/mapserv.exe?map=/ms4w/apps/Test/WFS_Test.map",
               {typename: "Sites",maxfeatures: 100 },{
               featureClass: OpenLayers.Feature.WFS.Marker});


function DumpResult(source, result){
    var s = "<plaintext>";
    s = s + source + " " + "\n";
    for (var x in result) {
      s = s + x + "=" + result[x] + "\n";
    }

    if (result.get_stackTrace) s = s + result.get_stackTrace() + "\n";
        s = s + "</pre>";
        document.getElementById("DebugDiv").innerHTML = s;
}

OpenLayers.Feature.WFS.Marker = OpenLayers.Class.create();
OpenLayers.Feature.WFS.Marker.prototype =
OpenLayers.Class.inherit( OpenLayers.Feature.WFS, {

/**
 * @constructor
 *
 * @param {OpenLayers.Layer} layer
 * @param {XMLNode} xmlNode
 */
initialize: function(layer, xmlNode) {
        var newArguments = arguments;
        var data = this.processXMLNode(xmlNode);
        newArguments = new Array(layer, data.lonlat, data)
        OpenLayers.Feature.prototype.initialize.apply(this, newArguments);
        DumpResult("initialize", this);
        this.createMarker();
        this.marker.events.register('click', this, this.markerClick);
        this.layer.addMarker(this.marker);
},

/**
 * @param {XMLNode} xmlNode
 *
 * @returns Data Object with 'id', 'lonlat', and private properties set
 * @type Object
 */
processXMLNode: function(xmlNode) {
        //this should be overridden by subclasses
        // must return an Object with 'id' and 'lonlat' values set
        var point = OpenLayers.Ajax.getElementsByTagNameNS(xmlNode,
                    "http://www.opengis.net/gml", "gml", "Point");
        var text =
OpenLayers.Util.getXmlNodeValue(OpenLayers.Ajax.getElementsByTagNameNS(point
                    [0], "http://www.opengis.net/gml","gml",
"coordinates")[0]);
        var floats = text.split(",");
        var gid =
OpenLayers.Util.getXmlNodeValue(OpenLayers.Ajax.getElementsByTagNameNS(xmlNode,
            "http://mapserver.gis.umn.edu/mapserver", "ms", "gid")[0]);

        //DumpResult("processXMLNode", text);
        //document.getElementById("DebugDiv").innerHTML = gid;
        return {lonlat: new OpenLayers.LonLat(parseFloat(floats[0]),
               parseFloat(floats[1])),id: gid, gid: gid};
},

/**
 * @param {Event} evt
 */
markerClick: function(evt) {
        DumpResult("markerClick", evt);
        OpenLayers.Event.stop(evt);
},

/** @final @type String */
CLASS_NAME: "OpenLayers.Feature.WFS.Marker"
});

//                  Create a vector layer for drawing
//            var vector = new OpenLayers.Layer.Vector("Editable Vectors");

            map.addLayers([gmap, gsat, ghyb, gphy,
                                        //veroad, veaer, vehyb,
                             sites, sitesconsul]); //, cables]);
            map.addControl(new OpenLayers.Control.LayerSwitcher());
            map.addControl(new OpenLayers.Control.ScaleLine);
//            map.addControl(new OpenLayers.Control.EditingToolbar(vector));
            map.addControl(new OpenLayers.Control.MousePosition());
           if (!map.getCenter()) {map.zoomToMaxExtent()}
        }

    function changezoom(x,y,z)
    {
    map.setCenter(new OpenLayers.LonLat(x, y), z);
    }
    function showAddress(address) {
       var geocoder = new GClientGeocoder();
     if (geocoder) {
       geocoder.getLatLng(
         address,
         function(point) {
           if (!point) {alert(address + " not found");}
           else {map.setCenter(new OpenLayers.LonLat(point.x,point.y),15);}
         }
       );
        }
    }
THANKS!!!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20080620/7ba4bcc0/attachment.html


More information about the Users mailing list