-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
executable file
·139 lines (123 loc) · 3.69 KB
/
index.html
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
127
128
129
130
131
132
133
134
135
136
137
138
139
<!DOCTYPE html>
<html>
<head>
<title>Icon Symbolizer</title>
<link rel="stylesheet" href="include/css/ol.css" type="text/css">
<script src="include/build/ol.js"></script>
<script src="include/jquery-2.2.3.min.js"></script>
<link rel="stylesheet" href="include/bootstrap.min.css">
<script src="include/bootstrap.min.js"></script>
<style>
#map {
position: relative;
width: 100%;
height: 645px;
.map:-moz-full-screen {
height: 100%;
}
.map:-webkit-full-screen {
height: 100%;
}
.map:fullscreen {
height: 100%;
}
/* position the rotate control lower than usual */
.ol-rotate {
top: 3em;
}
}
</style>
</head>
<body>
<div id="map" class="map"><div id="popup"></div></div>
<script src="include/mouse-position.js"></script>
<script>
var iconFeature = new ol.Feature({
geometry: new ol.geom.Point([-11002040.103255, 4635630.622052]),
name: 'Null Island',
population: 4000,
rainfall: 500
});
var iconStyle = new ol.style.Style({
image: new ol.style.Icon(/** @type {olx.style.IconOptions} */ ({
anchor: [0.5, 46],
anchorXUnits: 'fraction',
anchorYUnits: 'pixels',
src: 'img/folder-2.png'
}))
});
iconFeature.setStyle(iconStyle);
var vectorSource = new ol.source.Vector({
features: [iconFeature],
wrapX: false
});
var vectorLayer = new ol.layer.Vector({
source: vectorSource
});
var rasterLayer = new ol.layer.Tile({
source: new ol.source.OSM({
url: 'http://localhost/osm_tiles/{z}/{x}/{y}.png',
wrapX: false
})
});
var map = new ol.Map({
controls: ol.control.defaults({
attributionOptions: ({
collapsible: false
})
}).extend([mousePositionControl, new ol.control.FullScreen()]),
interactions: ol.interaction.defaults().extend([
new ol.interaction.DragRotateAndZoom()
]),
layers: [new ol.layer.Tile({
source: new ol.source.OSM({wrapX: false})
}),
rasterLayer,
vectorLayer],
target: document.getElementById('map'),
view: new ol.View({
center: [-11002040.103255, 4635630.622052],
//rotation: -Math.PI / 8,
zoom: 3
})
});
var element = document.getElementById('popup');
var popup = new ol.Overlay({
element: element,
positioning: 'bottom-center',
stopEvent: false,
offset: [0, -50]
});
map.addOverlay(popup);
// display popup on click
map.on('click', function(evt) {
var feature = map.forEachFeatureAtPixel(evt.pixel,
function(feature) {
return feature;
});
if (feature) {
var coordinates = feature.getGeometry().getCoordinates();
popup.setPosition(coordinates);
$(element).popover({
'placement': 'top',
'html': true,
'content': feature.get('name')
});
$(element).popover('show');
} else {
$(element).popover('destroy');
}
});
// change mouse cursor when over marker
map.on('pointermove', function(e) {
if (e.dragging) {
$(element).popover('destroy');
return;
}
var pixel = map.getEventPixel(e.originalEvent);
var hit = map.hasFeatureAtPixel(pixel);
map.getTarget().style.cursor = hit ? 'pointer' : '';
});
</script>
</body>
</html>