Repository navigation
Expand file tree
/
Copy pathExample.html
More file actions
126 lines (116 loc) · 3.93 KB
/
Copy pathExample.html
File metadata and controls
126 lines (116 loc) · 3.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<!DOCTYPE html>
<html>
<head>
<title>Accessible Map</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v6.15.1/css/ol.css" type="text/css">
<style>
.map {
height: 400px;
width: 100%;
}
</style>
<!-- The line below is only needed for old environments like Internet Explorer and Android 4.x -->
<script src="http://cdn.polyfill.io/v2/polyfill.min.js?features=requestAnimationFrame,Element.prototype.classList,URL"></script>
<script src="https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v6.15.1/build/ol.js"></script>
<script src="required/underscore.js"></script>
<script src="required/graph.js"></script>
<script src="OR-OL3.js"></script>
</head>
<body>
<button id="getPath">Get Path</button>
<div id="map" class="map" tabindex="0"></div>
<script>
var map = new ol.Map({
layers: [
new ol.layer.Tile({
source: new ol.source.OSM()
})
],
target: 'map',
controls: ol.control.defaults({
attributionOptions: /** @type {olx.control.AttributionOptions} */ ({
collapsible: false
})
}),
view: new ol.View({
projection: 'EPSG:4326',
center: [-5.811029 , 35.786934],
zoom: 16
})
});
var networkSource=new ol.source.Vector({
projection : 'EPSG:4326',
url: 'data-example/Tangier-Medina.geojson',
format: new ol.format.GeoJSON()
});
var networkLayer=new ol.layer.Vector({
title:'Tangier Old Medina roads',
source: networkSource,
style: new ol.style.Style({
fill: new ol.style.Fill({
color: 'rgba(255, 255, 255, 0.2)'
}),
stroke: new ol.style.Stroke({
color: '#737373',
width: 2
}),
image: new ol.style.Circle({
radius: 7,
fill: new ol.style.Fill({
color: '#ffcc33'
})
})
})
});
map.addLayer(networkLayer);
var sourceFeature = new ol.Feature({
geometry: new ol.geom.Point([ -5.808447003364563, 35.78528222343591]),
});
var sourceStyle = new ol.style.Style({
image: new ol.style.Icon(/** @type {olx.style.IconOptions} */ ({
anchor: [0.5, 0],
anchorOrigin: 'bottom-left',
anchorXUnits: 'fraction',
anchorYUnits: 'pixels',
src: 'img/marker-source.png'
}))
});
sourceFeature.setStyle(sourceStyle);
var destinationFeature = new ol.Feature({
geometry: new ol.geom.Point([ -5.812851190567017, 35.784746963605144]),
});
var destinationStyle = new ol.style.Style({
image: new ol.style.Icon(/** @type {olx.style.IconOptions} */ ({
anchor: [0.5, 0],
anchorOrigin: 'bottom-left',
anchorXUnits: 'fraction',
anchorYUnits: 'pixels',
src: 'img/marker-destination.png'
}))
});
destinationFeature.setStyle(destinationStyle);
var startEndSource = new ol.source.Vector({
features: [sourceFeature, destinationFeature]
});
var startEndLayer = new ol.layer.Vector({
source: startEndSource
});
map.addLayer(startEndLayer);
document.getElementById('getPath').onclick = function() {
var network=createNetwork(networkLayer.getSource().getFeatures());
var shortestPath=getShortestPath(network, [-5.808447003364563, 35.78528222343591], [-5.812851190567017, 35.784746963605144]);
var shortestPathLayer=new ol.layer.Vector({
source: new ol.source.Vector({
features: [new ol.Feature({
geometry: shortestPath
})]
}),
style: networkLayer.getStyle()
});
map.addLayer(shortestPathLayer);
shortestPathLayer.setVisible(true);
networkLayer.setVisible(false);
};
</script>
</body>
</html>