respec / leaflet.wfs-t

Leaflet plug-in for WFS Transactional (WFS-T) support
BSD 2-Clause "Simplified" License
42 stars 12 forks source link

Problem adding marker - no geometry field #1

Closed mtravis closed 10 years ago

mtravis commented 11 years ago

Hi Michael

I loaded a very simple point layer into my leaflet page with your plugin and leaflet draw all running fine with both markers showing.

When try and add a marker to the map I get: "no geometry field" error in the console.

Here's my code for the page.

Matt

'

    <link type="text/css" rel="stylesheet" href="css/map.css" />
    <script type="text/javascript" src="http://cdn.leafletjs.com/leaflet-0.6.4/leaflet.js"></script>
    <script type="text/javascript" src="http://localhost/leaflet/leaflet/Leaflet.draw/dist/leaflet.draw.js"></script>
    <script type="text/javascript" src="http://localhost/leaflet.wfs-t/js/leaflet.gml.js"></script>
    <script type="text/javascript" src="http://localhost/leaflet.wfs-t/js/leaflet.wfst.js"></script>
    <script type="text/javascript" src="js/map.js"></script>

</head>
    <body>
        <div id="map"></div>
    <script type="text/javascript">
        // Load the map with the initMap function in map.js

        var map = L.map('map').setView([50.370, -4.14], 14);

        var basemap = L.tileLayer('http://{s}.tile.cloudmade.com/a8ed148d84c2438ba62c2742cac051ae/33356/256/{z}/{x}/{y}.png', {
        maxZoom: 18,
        attribution: 'Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="http://cloudmade.com">CloudMade</a>'
    }).addTo(map);

layers = {};

layers.drawnItems = L.wfst(null,{
url : 'http://localhost/geoserver/wfs',
featureNS : 'cite',
featureType : 'points',
primaryKeyField: 'gid',
}).addTo(map);

    var drawControl = new L.Control.Draw({
    edit: {
    featureGroup: layers.drawnItems
}
});
map.addControl(drawControl);

map.on('draw:created', function (e) {
layers.drawnItems.addLayer(e.layer);
});
map.on('draw:edited', function (e) {
layers.drawnItems.wfstSave(e.layers);
});
xfido commented 11 years ago

I have this problem too.

tsemerad commented 11 years ago

I'm having the same issue. It looks like my GeoServer is sending the GML geometry element type as gml:SurfacePropertyType rather than gml:GeometryPropertyType.

It's at line 298 in leaflet.wfst.js

I tried adding the following to the if statement, but then it merely fails silently. || elems[p].getAttribute('type') == 'gml:SurfacePropertyType'

I believe the key lies in handling the geometry differently when it comes in as a gml:SurfacePropertyType. @stuporglue , do you have an idea on how to handle this? I hope this sheds some light on the issue.

stuporglue commented 11 years ago

Hi @tsemerad,

I'll need to look into gml:SurfacePropertyType. I'm climbing the gml and WFS-T learning curve as fast as I can, but I've still got a bit of ground to cover.

I'll try to look at this this weekend.

bartvde commented 10 years ago

I also had a layer which has gml:SurfacePropertyType and I had to make a few changes to be able to get a successful insert transaction:

diff --git a/js/leaflet.wfst.js b/js/leaflet.wfst.js
index 8605868..fae7799 100644
--- a/js/leaflet.wfst.js
+++ b/js/leaflet.wfst.js
@@ -315,8 +315,8 @@ L.WFST = L.GeoJSON.extend({
                     // Not sure what to do with null values yet. 
                     // At the very least Geoserver isn't liking null where a date should be.
                 }
-            }else if(elems[p].getAttribute('type') == 'gml:GeometryPropertyType'){
-                geomFields.push(elems[p]);
+            }else if(elems[p].getAttribute('type') == 'gml:GeometryPropertyType' || elems[p].getAttribute('type') === 'gml:MultiSurfacePropertyType'){
+                geomFields.push(elems[p].getAttribute('name'));
             }else if(elems[p].getAttribute('nillable') == 'false'){
                 if(elems[p].getAttribute('maxOccurs') != "1" && elems[p].getAttribute('minOccurs') != "1"){
                     console.log("No value given for required field " + attr);
@@ -332,13 +332,12 @@ L.WFST = L.GeoJSON.extend({
         ){
             if(this.options.geomField || geomFields.length === 1){
                 this.options.geomFields = this.options.geomField || geomFields[0];
-                field[attr] = layer.toGML();
+                field[this.options.geomFields] = layer.toGML();
             }else{
                 console.log("No geometry field!");
                 return false;
             }
         }
-
         return field;
     },
     // Make WFS-T filters for deleting/updating specific items

Basically the geometry attribute was always the last attribute that came back in the DescribeFeatureType request, which wouldn't work in my case. Also, geomFields got the raw XML element node instead of the name.

stuporglue commented 10 years ago

Thanks everyone,

I'm sorry for the long delay getting this fixed.

I have applied the changes @bartvde suggested and added MultiGeometryPropertyType and SurfacePropertyType too.

I'm going to assume that either

a) You've all fixed it for your local instances or b) You've moved on to other implementations c) that my latest commit actually fixes the problem (risky, I know!)

so, I'm going to close this issue and if anyone runs into it again, please re-open it or file a new issue.