[OpenLayers-Users] Unable to overlay a simple WFS

Smaran Harihar smaran.harihar at gmail.com
Tue May 15 11:58:03 PDT 2012


Hi Guys,

I am so tired of trying to over lay WFS. I am totally clueless. Have gone
through probably all the sites and gis.Stack but all have the same code but
it is not working for me?

I am not sure why is that the case. The firebug is giving me this error

XMLHttpRequest cannot load http://localhost:8080/geoserver/wfs. Origin
http://localhost is not allowed by Access-Control-Allow-Origin.

Here is my code,

<body>
       <h1>iPlant Map</h1>
       <div id="map-id"></div>
       <script>
           var map = new OpenLayers.Map("map-id");
           var bio = new OpenLayers.Layer.WMS(
             "bio11",
             "http://localhost:8080/geoserver/iPlant/wms",
             {layers: 'iPlant:bio11'}
           );
           var imagery = new OpenLayers.Layer.WMS(
               "Global Imagery",
               "http://maps.opengeo.org/geowebcache/service/wms",
               {layers: "bluemarble"}
           );

           /*var QuebecSpecies = new OpenLayers.Layer.WMS(
             "AllQuebecSpecies",
             "http://localhost:8080/geoserver/iPlant/wms",
             {layers: 'iPlant:AllQuebecSpecies'},
             {'opacity': 0.4, 'isBaseLayer': false, 'visibility': true}
           );*/

           var QuebecSpecies = new OpenLayers.Layer.Vector(
           "AllQuebecSpecies",
           {
               strategies: [new OpenLayers.Strategy.Fixed()],
               projection: new OpenLayers.Projection("EPSG:4326"),
               visibility: true,
               protocol: new OpenLayers.Protocol.WFS({
                   version: "1.1.0",
                   url: "http://localhost:8080/geoserver/wfs",
                   featurePrefix: 'iPlant', //geoserver worspace name
                   featureType: "iPlant:AllQuebecSpecies", //geoserver
Layer Name
                   featureNS: "http://geoserver.org/iPlant", // Edit
Workspace Namespace URI
                   geometryName: "the_geom" // field in Feature Type
details with type "Geometry"
               })
           });

           QuebecSpecies.refresh();
           map.addLayers([imagery, bio, QuebecSpecies]);
//map.addLayers([imagery, bio, vectors]);
           map.addControl(new OpenLayers.Control.LayerSwitcher());
           map.addControl(new OpenLayers.Control.MousePosition({element:
$('location')}));
           map.events.register("mousemove", map, function(e) {
               var latlon = map.getLonLatFromViewPortPx(e.xy) ;
               var lat = Math.round(latlon.lat);
               var lon = Math.round(latlon.lon);
               OpenLayers.Util.getElement("location").innerHTML = "The
Latitude is " + lat +
       " and the Longitude is " + lon;


           map.zoomToMaxExtent();
       </script>
       <div id="location">Position</div>
</body>

Please tell me where am I going wrong?

-- 
Thanks & Regards
Smaran Harihar
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20120515/3b360b8d/attachment.html


More information about the Users mailing list