[mapguide-users] WFS Connection from OpenLayers

Johan Van de Wauw johan.vandewauw at gmail.com
Thu Jun 27 00:03:58 PDT 2013


Here is some openlayers wfs code that works with mapguide.  I'm also
forcing WFS 1 and GML 2 since they are simpler. You probably want to
switch the extent and the projection system to something else than
belgium :-)

var mapagent = "/mapguide/mapagent/mapagent.fcgi";

   var extent = new OpenLayers.Bounds(22000, 150000, 259000, 245000);


    var mapOptions = {
        units: "m",
        projection: "EPSG:31370",
        maxExtent: extent
    };
    map = new OpenLayers.Map('map', mapOptions);

    var styles = new OpenLayers.StyleMap({
        "default": new OpenLayers.Style(null, {
            rules: [
                new OpenLayers.Rule({
                    symbolizer: {
                        "Point": {
                            pointRadius: 5,
                            graphicName: "square",
                            fillColor: "white",
                            fillOpacity: 0.25,
                            strokeWidth: 1,
                            strokeOpacity: 1,
                            strokeColor: "#3333aa"
                        },
                        "Line": {
                            strokeWidth: 3,
                            strokeOpacity: 1,
                            strokeColor: "#ff0000"
                        },
                        "Polygon": {
                            strokeWidth: 1,
                            strokeOpacity: 1,
                            fillColor: "#9999aa",
                            strokeColor: "#6666aa"
                        }
                    }
                })
            ]
        }),

    });

    var renderer = OpenLayers.Layer.Vector.prototype.renderers;
    var wfs_options = {
        url: mapagent,
        params: {
            REQUEST: "GETFEATURE",
            SERVICE: "WFS",
            VERSION: "1.0.0",
            TYPENAME: "namespacexxx:xxxxx",
            OUTPUTFORMAT: "GML2",
            SRSNAME: "EPSG:31370"
        },
        format: new OpenLayers.Format.GML(),
        renderers: renderer
    }



    var wfs = new OpenLayers.Layer.Vector(
    "name",
    {
        strategies: [new OpenLayers.Strategy.BBOX()]
        , visibility: true
      , featureType: "xxxxxxx"
        , protocol: new OpenLayers.Protocol.HTTP(wfs_options)
        , geometryName: "Geometry",
        styleMap: styles,
        minScale : 100000

    });

    map.addLayer(wfs);

On Wed, Jun 19, 2013 at 7:38 PM, Rich Bauer <rdbauer at gmail.com> wrote:
> I have gotten a little farther and am running into an error that I believe
> might be MapGuide related. MgStreamIoException?
>
> POST
> http://localhost/mapguide/mapagent/mapagent.fcgi?USERNAME=Administrator&Password=admin
> 559 (MgStreamIoException) XMLHttpRequest.js:220
>
> fXMLHttpRequest_sendXMLHttpRequest.js:220
> cXMLHttpRequest.sendXMLHttpRequest.js:262
> (anonymous function)Request.js:240
>
> XHR finished loading:
> "http://localhost/mapguide/mapagent/mapagent.fcgi?USERNAME=Administrator&Password=admin".
> XMLHttpRequest.js:220
>
> fXMLHttpRequest_sendXMLHttpRequest.js:220
> cXMLHttpRequest.sendXMLHttpRequest.js:262
> (anonymous function)Request.js:240
>
>
> The response preview is:
>
> A stream IO exception occurred.
>
> A stream IO exception occurred.- IsapiAgent.HttpExtensionProc() line 211
> file IsapiAgent.cpp- IsapiPostParser.Parse() line 196 file
> IsapiPostParser.cpp
>
> I didn't see anything in the server logs through the Site Administrator that
> stood out to me as being related to this. I can post code if it would help.
>
> Thanks,
> Rich
>
>
> On Fri, Jun 14, 2013 at 12:39 PM, Rich Bauer <rdbauer at gmail.com> wrote:
>>
>> FYI...I also posted in the OpenLayers list because I am not sure now if it
>> is OpenLayers or MapGuide related.
>>
>> OpenLayers link:
>> http://osgeo-org.1560.x6.nabble.com/Connecting-to-MapGuide-via-WFS-td5060238.html
>>
>>
>> On Fri, Jun 14, 2013 at 12:14 PM, Rich Bauer <rdbauer at gmail.com> wrote:
>>>
>>> Update...
>>>
>>> I stumbled across something that creates the WFS connection from a WMS
>>> Layer. I tried this earlier but evidently had the code wrong. Both layers
>>> show up in the Layers panel as it is added to the map, but the WMS layer
>>> shows up and the created WFS does not.  Code below:
>>>
>>> var wmsParcels = new OpenLayers.Layer.WMS("Parcels",
>>>
>>> "http://localhost/mapguide/mapagent/mapagent.fcgi?USERNAME=Administrator&Password=admin",
>>>         { layers: 'Samples/Sheboygan/Layers/Parcels', transparent: true
>>> },
>>>         { isBaseLayer: false, transitionEffect: 'resize', format:
>>> 'image/png' }
>>>         //{ projection: new OpenLayers.Projection('EPSG:900913') }
>>>     );
>>>
>>> map.addLayer(wmsParcels);
>>>
>>> var wfsParcels = new OpenLayers.Layer.Vector("WFS Parcels", { protocol:
>>> new OpenLayers.Protocol.WFS.fromWMSLayer(wmsParcels) });
>>>
>>> map.addLayers([select, wfsParcels]);
>>>
>>> With this there are no errors showing up in Chrome.
>>>
>>>
>>>
>>> On Fri, Jun 14, 2013 at 7:37 AM, RDBauer <rdbauer at gmail.com> wrote:
>>>>
>>>> All,
>>>>
>>>> I have searched the list and Google and have not been able to find what
>>>> I
>>>> need. I am trying to connect to MapGuide (2.5 on test machine but 2.2 on
>>>> production machine right now) from OpenLayers 2.12. I know that it would
>>>> be
>>>> easier to use Fusion, but it currently doesn't have the support for
>>>> Mobile
>>>> and that is what I need. Also, I can't use PHP or .NET for any code
>>>> because
>>>> it will be packaged in PhoneGap for a mobile app. Right now I am just
>>>> trying
>>>> to connect to the sample dataset to get things working and also, by
>>>> actual
>>>> data will most likely be served as the same WGS projection. My current
>>>> code
>>>> is:
>>>>
>>>>
>>>> /map = new OpenLayers.Map({
>>>>         div: "map",
>>>>         theme: null,
>>>>         projection: osmProj,
>>>>         displayProjection: wgs,
>>>>         maxExtent: extent,
>>>>         scales: tempScales,
>>>>         controls: [
>>>>             new OpenLayers.Control.Attribution(),
>>>>             new OpenLayers.Control.TouchNavigation({ dragPanOptions: {
>>>> enableKinetic: true } }),
>>>>             //new
>>>> OpenLayers.Control.Scale(document.getElementById("mapScale"))
>>>>         geolocate
>>>>         //selectControl
>>>>         ]
>>>>     });
>>>>
>>>> var layer = new OpenLayers.Layer.MapGuide("Sheboygan Tiled Layer", url,
>>>> params, options);
>>>>
>>>> var wfsParcels = new OpenLayers.Layer.Vector("WFS Parcels", {
>>>>         strategies: [new OpenLayers.Strategy.Fixed()],
>>>>         protocol: new OpenLayers.Protocol.WFS({
>>>>             //version: "1.1.0",
>>>>             srsName: "EPSG:4326",
>>>>             url:
>>>>
>>>> "http://localhost/mapguide/mapagent/mapagent.fcgi?USERNAME=Administrator&Password=admin",
>>>>             featureType: "ns34414117:ParcelsType",
>>>>             featureNS: "http://www.opengis.net/gml",
>>>>             geometryName: "SHPGEOM"
>>>>         }),
>>>>         styleMap: new OpenLayers.StyleMap({
>>>>             strokeWidth: 3,
>>>>             strokeColor: "#333333"
>>>>         })
>>>>         //projection: wgs
>>>>     });
>>>>
>>>> map.addLayer(layer);
>>>> map.addLayer(wfsParcels);
>>>> map.zoomToExtent(extent);/
>>>>
>>>> With this current code, I get the following error in Chrome Developer
>>>> Tools:
>>>>
>>>> /Failed to load resource: Origin null is not allowed by
>>>> Access-Control-Allow-Origin.
>>>>
>>>> http://localhost/mapguide/mapagent/mapagent.fcgi?USERNAME=Administrator&Password=admin
>>>>
>>>> XMLHttpRequest cannot load
>>>>
>>>> http://localhost/mapguide/mapagent/mapagent.fcgi?USERNAME=Administrator&Password=admin.
>>>> Origin null is not allowed by Access-Control-Allow-Origin. index.html:1/
>>>>
>>>> Things I am not sure about if they are correct are the "featureType" &
>>>> "featureNS". I got those from the GETCAPABILITIES command. Any thoughts?
>>>>
>>>> Thanks,
>>>> Rich
>>>>
>>>>
>>>>
>>>> --
>>>> View this message in context:
>>>> http://osgeo-org.1560.x6.nabble.com/WFS-Connection-from-OpenLayers-tp5060185.html
>>>> Sent from the MapGuide Users mailing list archive at Nabble.com.
>>>> _______________________________________________
>>>> mapguide-users mailing list
>>>> mapguide-users at lists.osgeo.org
>>>> http://lists.osgeo.org/mailman/listinfo/mapguide-users
>>>
>>>
>>
>
>
> _______________________________________________
> mapguide-users mailing list
> mapguide-users at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/mapguide-users
>


More information about the mapguide-users mailing list