123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- <!--********************************************************************
- * Copyright© 2000 - 2021 SuperMap Software Co.Ltd. All rights reserved.
- *********************************************************************-->
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="UTF-8">
- <title data-i18n="resources.title_closestFacilitiesService"></title>
- <script type="text/javascript" src="../js/include-web.js"></script>
- <script type="text/javascript" src="../../dist/ol/include-ol.js"></script>
- </head>
- <body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%; position: absolute;top: 0;">
- <div id="map" style="width: 100%;height:100%"></div>
- <script type="text/javascript">
- var map, options,
- baseUrl = (window.isLocal ? window.server : "https://iserver.supermap.io")+"/iserver/services/map-changchun/rest/maps/长春市区图",
- serviceUrl = (window.isLocal ? window.server : "https://iserver.supermap.io")+"/iserver/services/transportationanalyst-sample/rest/networkanalyst/RoadNet@Changchun";
- var extent = [48.4, -7668.25, 8958.85, -55.58];
- var projection = new ol.proj.Projection({
- code:'',
- extent: extent,
- units: 'm'
- });
- new ol.supermap.MapService(baseUrl).getMapInfo(function (serviceResult) {
- var mapJSONObj = serviceResult.result;
- map = new ol.Map({
- target: 'map',
- controls: ol.control.defaults({attributionOptions: {collapsed: false}})
- .extend([new ol.supermap.control.Logo()]),
- view: new ol.View({
- center: [5000, -3700],
- zoom: 2,
- projection: projection,
- multiWorld: true
- })
- });
- options = ol.source.TileSuperMapRest.optionsFromMapJSON(baseUrl, mapJSONObj);
- var layer = new ol.layer.Tile({
- source: new ol.source.TileSuperMapRest(options)
- });
- map.addLayer(layer);
- findClosetFacilitiesProcess();
- });
- function findClosetFacilitiesProcess() {
- //添加设施点
- var facilityPoint1 = new ol.geom.Point([2500, -3500]);
- var facilityPoint2 = new ol.geom.Point([5500, -2500]);
- var facilityPoint3 = new ol.geom.Point([7000, -4000]);
- var facilityFeature1 = new ol.Feature(facilityPoint1);
- var facilityFeature2 = new ol.Feature(facilityPoint2);
- var facilityFeature3 = new ol.Feature(facilityPoint3);
- var iconStyle_facility = new ol.style.Style({
- image: new ol.style.Icon(({
- src: '../img/marker-gold.png'
- }))
- });
- facilityFeature1.setStyle(iconStyle_facility);
- facilityFeature2.setStyle(iconStyle_facility);
- facilityFeature3.setStyle(iconStyle_facility);
- var facilitySource = new ol.source.Vector({
- features: [facilityFeature1, facilityFeature2, facilityFeature3]
- });
- var facilityLayer = new ol.layer.Vector({
- source: facilitySource
- });
- //添加事件点
- var eventPoint = new ol.geom.Point([5000, -3700]);
- var eventFeature = new ol.Feature(eventPoint);
- var iconStyle_event = new ol.style.Style({
- image: new ol.style.Icon(({
- src: '../img/marker.png'
- }))
- });
- eventFeature.setStyle(iconStyle_event);
- var eventSource = new ol.source.Vector({
- features: [eventFeature]
- });
- var eventLayer = new ol.layer.Vector({
- source: eventSource
- });
- //创建最近设施分析参数实例
- var resultSetting = new SuperMap.TransportationAnalystResultSetting({
- returnEdgeFeatures: true,
- returnEdgeGeometry: true,
- returnEdgeIDs: true,
- returnNodeFeatures: true,
- returnNodeGeometry: true,
- returnNodeIDs: true,
- returnPathGuides: true,
- returnRoutes: true
- });
- var analystParameter = new SuperMap.TransportationAnalystParameter({
- resultSetting: resultSetting,
- turnWeightField: "TurnCost",
- weightFieldName: "length" //length,time
- });
- var findClosetFacilitiesParameter = new SuperMap.FindClosestFacilitiesParameters({
- //事件点,必设参数
- event: new ol.geom.Point([5000, -3700]),
- //要查找的设施点数量。默认值为1
- expectFacilityCount: 1,
- //设施点集合,必设
- facilities: [new ol.geom.Point([2500, -3500]), new ol.geom.Point([5500, -2500]), new ol.geom.Point([7000, -4000])],
- isAnalyzeById: false,
- parameter: analystParameter
- });
- //进行查找
- new ol.supermap.NetworkAnalystService(serviceUrl).findClosestFacilities(findClosetFacilitiesParameter, function (serviceResult) {
- serviceResult.result.facilityPathList.map(function (result) {
- var vectorSource = new ol.source.Vector({
- features: (new ol.format.GeoJSON()).readFeatures(result.route)
- });
- var pathLayer = new ol.layer.Vector({
- source: vectorSource,
- style: new ol.style.Style({
- stroke: new ol.style.Stroke({
- color: 'rgba(100, 100, 225, 10)',
- width: 3
- }),
- fill: new ol.style.Fill({
- color: 'rgba(0, 0, 255, 0.1)'
- })
- })
- });
- map.addLayer(pathLayer);
- });
- map.addLayer(facilityLayer);
- map.addLayer(eventLayer);
- });
- }
- </script>
- </body>
- </html>
|