Their shortest path implementation is basically in accordance with the reference post of 1, 2 and 3, the implementation of the time is also a problem, can only be a solution.
Issue 1: The GeoServer service I published cannot be superimposed with the OSM basemap.
Resolution: Refer to post 2 refers to the release of the service needs to set the projection to 900913, I think the big can not, still use 4326 can be, just openlayers loaded when the relevant parameters can be configured, as follows:
//Defining Map Boundaries //var bounds= new Openlayers.bounds (12960129.562300, 4788641.902700, 12986389.084400, 4817845.581900); varBounds =NewOpenlayers.bounds (116.145027, 39.756095, 116.703957, 40.027940); varOptions ={projection:"epsg:900913", Displayprojection:NewOpenlayers.projection (' epsg:4326 '), center:NewOpenlayers.lonlat (116.46760559087, 39.936089796286), MaxExtent:bounds.transform (NewOpenlayers.projection ("epsg:4326"), NewOpenlayers.projection ("epsg:900913") ) }; Map=NewOpenlayers.map (' Map_element ', Options); varOsmlayer =NewOpenLayers.Layer.OSM (); Map.addlayer (Osmlayer); varBaselayer =NewOpenLayers.Layer.WMS ("Openlayers WMS", //GeoServer server Address' Http://localhost:8080/geoserver/ProjectLLL/wms ', {layers:' Projectlll:beijing_line ', Format:"Image/png", Transparent:true, Styles:‘‘,}, {isbaselayer:false, Singletile:true, ratio:1 } ); //var baselayer = new OpenLayers.Layer.OSM ();Map.addlayer (Baselayer); //Add control SpaceMap.addcontrol (NewOpenLayers.Control.MousePosition ()); Map.addcontrol (NewOpenLayers.Control.ScaleLine ()); Map.addcontrol (NewOpenLayers.Control.Scale); Map.zoomtoextent (bounds);
The projection of the OSM Basemap is 900913, set the code:
Projection: "epsg:900913", displayprojection:new openlayers.projection (' epsg:4326 '),
You can stack the two together.
Problem 2:navigation parameter issues for layers
FIX: The parameter follows the following settings, navigation is also a layer, but an empty layer with the SQL statement, when the request to GeoServer, the SQL statement will be executed automatically to get the layer.
result = new OpenLayers.Layer.WMS ("Navlayer",
' Http://localhost:8080/geoserver/ProjectLLL/wms ',
{ FORMAT: ' Image/png ',
Transparent:true,
LAYERS: ' Projectlll:navigation ',
Viewparams:viewparams,
Styles: ' ShortPath '
},
{Isbaselayer:false,
Opacity:1,
}
);
In question 1, the layer you published is also loaded on the OSM basemap, which can be operated directly on the OSM basemap without loading it, and GeoServer will return the results of the shortest path displayed on the OSM basemap.
Question 3: How do I write the shortest path SQL statement? Is critical
Solution: The core algorithm uses Dijkstra algorithm, the first main reference 1 and 42 articles write SQL statements, but always get the final result, tried many many times, all failed, the mood few words said not clear AH. The method in 4 is clear, clear-minded, but always error-prone. 1 The method is generally rough, also said that the pass, consider not thoughtful, but also do not know what ghost error, debugging countless times have no results. Finally in desperate despair, inadvertently, see Writing a pl/pgsql wrapper (http://workshop.pgrouting.org/chapters/wrapper.html) This is the official out of a help note, Inside also said a method and 1 of the method is similar, I used this to try a, suddenly became, too suddenly, the official website of the things are not how to see, now it seems that the official website of the things are very practical.
Finally, the main is in accordance with the code framework given in 3, the parameters and so on to adjust, and finally to achieve the shortest path query, but the SQL algorithm is a bit rough to write, there is time to change.
Reference blog:
1, the shortest path query function between any two points based on pgrouting
2. Create a WMS service based on GeoServer in the shortest path planning
3, the shortest path planning based on Openlayers (1, 2 and 3 and the previous 1 and 2 are a series, this series basically covers the entire process, but it is also the problem of implementation. The best way is to understand other people's thinking, according to their own machine environment to modify or rewrite the code of others, and finally achieved.
4, use pgrouting to seek any two points of the shortest path (and my previous 4 is a series, this article inside the idea is very good, but I have tried many times did not realize, only hanhen and finally)
postgresql+postgis+pgrouting Implement Shortest Path Query (2)---openlayers+geoserver Implement shortest Path