wfs方式获取最短路径

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/longshengguoji/article/details/50825168

之前有几篇文章结束基于pgrouting的最短路径规范,获取最短路径用的是wms方式,这样的好处就是路径样式可以预先是geoserver中设置好,且路径渲染由geoserver在后台渲染。但是用户的需求是无穷无尽的,加入用户要求结果路径的样式需要动环效果该怎么做呢?

         Wms方式获取的地图是后台渲染好的图片,如果要在前端做出动画效果,就需要用wfs的方式来请求最短路径了,这样做的思路是先获取到结果路径中的点坐标,拿到了点数据,剩下的动画啦、样式啦就可以随心所欲的制作了。

         核心代码如下,体验一下吧

var vectorSource = new ol.source.ServerVector({
                format: new ol.format.GeoJSON(),
                loader: function(extent, resolution, projection) {
                    var url = 'http://10.20.135.25/geoserver/wfs';
                    $.ajax({
                        url: url,
						data : $.param(wfsParams),
						type : 'GET',
                        dataType: 'jsonp',
						jsonpCallback:'loadFeatures'
						
                    }).done(loadFeatures);
                },
                strategy: ol.loadingstrategy.createTile(new ol.tilegrid.XYZ({
                    maxZoom: 25
                })),
                projection: 'EPSG:4326'
            });
			 // Executed when data is loaded by the $.ajax method.
            var loadFeatures = function(response) {
                vectorSource.addFeatures(vectorSource.readFeatures(response));
				
            };
			// Vector layer
            var vectorLayerJsonp = new ol.layer.Vector({
                source: vectorSource,
                style: new ol.style.Style({
                    stroke: new ol.style.Stroke({
                        color: 'green',
                        width: 2
                    })
                })
            });
			map.addLayer(vectorLayerJsonp);


展开阅读全文

wfs例子上的问题

08-12

在 http://openlayers.org/dev/examples/wfs-states.html (官网例子)中可用看到橙黄色的美国States图层覆盖在上面,我把openlayers官网里的 wfs美国领土states例子下到自己的电脑上,当然是html和js文件都下了,但是在自己的机子上却只能看见底图(http://labs.metacarta.com/wms-c/Basic.py 的basic图层)。rnrn下面是两段源码:rn[b]wfs-states.js代码:[/b]rnvar map;rnOpenLayers.ProxyHost = "proxy.cgi?url=";rnrnfunction init() rn map = new OpenLayers.Map("map");rnrn var base = new OpenLayers.Layer.WMS("OpenLayers WMS",rn "http://labs.metacarta.com/wms-c/Basic.py",rn layers: "basic" rn );rn map.addLayer(base);rnrn var wfs = new OpenLayers.Layer.Vector("States", rn strategies: [new OpenLayers.Strategy.BBOX()],rn protocol: new OpenLayers.Protocol.WFS(rn url: "http://demo.opengeo.org/geoserver/wfs",rn featureType: "states",rn featureNS: "http://www.openplans.org/topp"rn )rn );rn map.addLayer(wfs);rnrn map.zoomToExtent(new OpenLayers.Bounds(-140.4, 25.1, -44.4, 50.5));rnrnrn[b]wfs-states.html代码:[/b]rnrn rn rn rn WFS: United States (GeoServer)rn rn rn rnrn rn WFS United States (GeoServer) Examplern rn rn Shows the use of the WFS United States (GeoServer). rn rn rn rn rnrn This example shows the basic use of a vector layer with thern WFS protocol.rn rn rn See the wfs-states.jsrn source to see how this is done.rn rn rn rnrnrn文件放置的目录应该是没错的……大家有遇见这种情况的吗?rn本地显示[img=http://geekjack.hostesr.com/1.png]rnrn官网例子显示&span&span&span[align=right][/img][img=http://geekjack.hostesr.com/2.png][/img][/align] 论坛

没有更多推荐了,返回首页