demo (#22) - Question to foss4g-workshop (2007) (#245) - Message List

Question to foss4g-workshop (2007)

Dear users,

I try to use the foss4g-tutorial. With the victoria-data it works fine. I try now my own data (Data from Osnabrueck).

I try  http://localhost/openlayers/workshop/foss4g_w12/04_ax_routing.php?startpoint=897762.4517129612%206849961.616593762&finalpoint=897270.3883434439%206849116.031968475&method=SPD&srid=900913

and get:

<route>

<edge id="1">

<id>7765647</id> −

<wkt>

MULTILINESTRING((897637.103870886 6849903.67335111,897619.270488462 6849960.09014959,897618.179557452 6849986.92510842,897659.467956587 6850071.72416528,897747.310166772 6850083.6590537)) </wkt> <length>0.269</length> </edge> −

<edge id="2">

<id>7765770</id> −

<wkt>

MULTILINESTRING((897637.103870886 6849903.67335111,897621.797440902 6849879.62219488,897609.518901068 6849851.13203757,897527.654547539 6849671.02417726,897533.131466486 6849651.70375479,897528.444915924 6849643.35341702,897523.736101463 6849635.02128034,897505.090086755 6849615.48263551,897485.575780019 6849568.92845745,897428.758311918 6849449.46064178,897342.830796975 6849292.91991373,897328.114360292 6849260.52063766,897275.30439386 6849133.48980754,897260.743804464 6849107.11246947,897219.377481685 6849093.12341968)) </wkt> <length>1.201</length> </edge> </route>

.....what should be a sign of success, shouldn`t it?

But Firebug always says:

parser has no properties and means:

for (var i = 0; i < edges.length; i++) {

var g = parser.read(edges[i].getElementsByTagName('wkt')[0].textContent); features.push(new OpenLayers?.Feature.Vector(g));

}

in 06.index.html

Has anybody any idea what creates that error?

Thank you very much, Kai

  • Message #869

    Well, I think it doesn`t has someting to do with my data, it has something to do with the OpenLayers?.lib.

    If I use <script src="./OpenLayers-google/lib/OpenLayers.js"></script> with the victoria-data it works.

    If I use <script src="../../lib/OpenLayers.js"></script> from OL 2.7 I get the error with the victoria-data as well.

    The problem with the new library seems to be something with the parser-code.

    parser = new OpenLayers?.Format.WKT();

    var wkt = "POLYGON((880000 6860000, 880000 6840000, 915000 6840000, 915000 6860000, 880000 6860000))"; var geometry = parser.read(wkt); var feature = new OpenLayers?.Feature.Vector(geometry);

    downtown.addFeatures([feature]);

    e.g gives me:

    feature.geometry.getBounds is not a function [Break on this error] var bounds = feature.geometry.getBounds();

    Well, I will try on.......

    • Message #870

      Hallo Kai,

      The OpenLayers? version of the 2007 workshop is very old. It's a sandbox version of 1.5, because it was the beginning of vector layer support with necessary Google Maps projection hack. Sorry for that but I never had the time to review this.

      The Javascript part was done by Camptocamp. While I think it's nice how they did, I would recommend you to create a JSON object in PHP instead of an XML. OpenLayers? and Firebug then make it easy to parse that object and you can use console.info() to output debug information.

      I would recommend you to use the latest version of OpenLayers?.

      The JSON part would then look similar to this:

      // Take your AJAX response and create an object
      var json = new OpenLayers.Format.JSON().read(response);
      // Probably you still have your geometry as WKT
      var parser = new OpenLayers.Format.WKT();
      // I use jQuery here, but it's just a loop through your linestring features
      jQuery.each(json.features, function(i)
          {
              feature = parser.read(this.wkt);
              mylayer.addFeatures([feature]);
          }
      });
      
      • Message #871

        Hi Daniel, thank you very much, I will try this. If I get it to run I`m going to write a tutorium here in the wiki how the routing works with Open Layers 2.7.

        • Message #872

          It works now.

          Somehow there were problems with feature=parser.read(wkt)

          I took now

          function parseWKT(wkt) {

          parser = new OpenLayers?.Format.WKT();

          // var wkt = "POLYGON((880000 6860000, 880000 6840000, 915000 6840000, 915000 6860000, 880000 6860000))";

          var geometry = parser.read(wkt)

          // var element = document.getElementById('wkt');

          var features = parser.read(wkt); var bounds; if(features) {

          if(features.constructor != Array) {

          features = [features];

          } for(var i=0; i<features.length; ++i) {

          if (!bounds) {

          bounds = features[i].geometry.getBounds();

          } else {

          bounds.extend(features[i].geometry.getBounds());

          }

          }

          downtown.addFeatures(features);

          // map.zoomToExtent(bounds);

          // var plural = (features.length > 1) ? 's' : ; // element.value = 'Feature' + plural + ' added'

          } else { alert ("wrong");

          element.value = 'Bad WKT';

          }

          }

          So, I`m going to start to develop the tutorial now in the wiki :-)

      • Message #1717

        Hallo Daniel
        can I ask you how can I access response from route generated according your tutorial 2010 where you use geoext store please.
        There is this part :

        var store = new GeoExt.data.FeatureStore({
            layer: route_layer,
            fields: [
                {name: 'length'}
            ],
        	proxy: new GeoExt.data.ProtocolProxy({
                protocol: new OpenLayers.Protocol.HTTP({
                    url: './php/pgrouting.php',
                    format: new OpenLayers.Format.GeoJSON({
                        internalProjection: epsg_900913,
                        externalProjection: epsg_4326
                    })
                })
            })
        });
        


        ...and I would like to get atribute values of length from each segment of generated route.
        Should I add listener to this route? and what should be in it?

        thank you in advance for help

        • Message #1719

          Take the 2010 workshop and just change the data (table) if you want to use Canada data. But look if the network table has the same attributes and projection.

          I don't know well anymore about the 2007 workshop and it's really old and outdated, so better to take it offline maybe.

          • Message #1734

            in meantime I found one of solutions :

             // create a grid to display records from the store
                var gridPanel = new Ext.grid.GridPanel({
                   store: store,
                   cm: new Ext.grid.ColumnModel([
                        {id: "length", header: "Length [m]", dataIndex: "length", sortable: true, width: 80}
                    ]),
                    sm: new Ext.grid.RowSelectionModel({singleSelect:true}),
             	height: 300,
                    width: 350
                });
            
          • Message #1721

            Yes, this sample was from workshop 2010 where you used geojson for putting route into the map.
            It work fine like you describe it but my question was how can I, for example by javascript alert show all length of all segments of generated route.