demo (#22) - Question to foss4g-workshop (2007) (#245) - Message List
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).
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.......
Kai-Behncke04/10/09 00:12:30 (20 months ago)-
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]); } });
daniel04/10/09 09:46:52 (20 months ago)-
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.
Kai-Behncke04/10/09 21:08:22 (20 months ago)-
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 :-)
Kai-Behncke04/11/09 02:06:52 (20 months ago)
-
-
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
Dzouzeph10/22/10 07:20:39 (4 weeks ago)-
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.
daniel10/22/10 09:30:32 (4 weeks ago)-
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 });
Dzouzeph11/01/10 17:58:06 (3 weeks ago) -
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.Dzouzeph10/22/10 16:19:03 (4 weeks ago)
-
-
-
-