The location you clicked was:
${hdms}`;
127 | $(element).popover('destroy');
128 | $(element).popover({
129 | 'placement': 'top',
130 | 'animation': false,
131 | 'html': true,
132 | 'content': div
133 | });
134 | $(element).popover('show');
135 | } else {
136 | element.childNodes.forEach((child) => {
137 | if (child.id === 'popup-content') {
138 | child.innerHTML = `The location you clicked was:
${hdms}`;
139 | } else if (child.id === 'popup-closer') {
140 | child.onclick = this.onCloseClick.bind(this, overlay, this.options.add);
141 | }
142 | });
143 | }
144 | }
145 |
146 | onCloseClick(overlay, add) {
147 | if (add) {
148 | this.ol2d.removeOverlay(overlay);
149 | } else {
150 | overlay.setPosition(undefined);
151 | }
152 | }
153 |
154 | addOverlay() {
155 | let element;
156 | if (this.options.boostrap) {
157 | element = document.getElementById('popup-bootstrap').cloneNode(true);
158 | } else {
159 | element = document.getElementById('popup').cloneNode(true);
160 | }
161 | const overlay = new olOverlay({element});
162 | this.ol2d.addOverlay(overlay);
163 | return overlay;
164 | }
165 | }
166 |
167 | new OverlayHandler(ol2d, ol3d, scene);
168 |
169 | document.getElementById('enable').addEventListener('click', () => ol3d.setEnabled(!ol3d.getEnabled()));
170 |
171 | //##REMOVE## Keep this tag, split code here for code sandbox
172 |
173 | import {initCodeSandbox} from './_code-sandbox.js';
174 | initCodeSandbox('rawjs/overlay.js');
175 |
--------------------------------------------------------------------------------
/examples/_code-sandbox.js:
--------------------------------------------------------------------------------
1 | const lzScript = document.createElement('script');
2 | lzScript.src = 'https://cdn.jsdelivr.net/npm/lz-string@1.4.4/libs/lz-string.min.js';
3 | document.head.appendChild(lzScript);
4 |
5 | function compress(json) {
6 | return window.LZString.compressToBase64(JSON.stringify(json))
7 | .replace(/\+/g, '-')
8 | .replace(/\//g, '_')
9 | .replace(/=+$/, '');
10 | }
11 |
12 | export async function initCodeSandbox(indexJsPath, ...filesPathes) {
13 | const response = await fetch(indexJsPath);
14 | const txtData = await response.text();
15 | const indexJsContent = txtData.split('//##REMOVE##')[0];
16 | const additionalJsFiles = {};
17 | const resourcesFiles = filesPathes
18 | .filter(path => path.indexOf('data/') === 0)
19 | // eslint-disable-next-line arrow-body-style
20 | .map(path => ({
21 | [path]: {
22 | 'isBinary': true,
23 | content: `https://openlayers.org/ol-cesium/examples/${path}`
24 | }
25 | }));
26 | const jsFiles = filesPathes.filter(path => !path.startsWith('data/'));
27 |
28 | for (const filePath of jsFiles) {
29 | const responseFile = await fetch(filePath);
30 | const txtDataFile = await responseFile.text();
31 |
32 | additionalJsFiles[filePath.replace('./', '').replace('rawjs', '')] = {content: txtDataFile};
33 | }
34 |
35 | initCodeSandboxButton({indexJsContent, additionalJsFiles, resourcesFiles});
36 | }
37 |
38 | function initCodeSandboxButton(options) {
39 | const {indexJsContent, additionalJsFiles, resourcesFiles} = options;
40 |
41 | let indexHtmlContent = '';
42 | const button = document.getElementById('sandbox-button');
43 | const form = document.querySelector('#sandbox-form');
44 |
45 | if (!button || !form) {
46 | return;
47 | }
48 |
49 | const divExampleCodeSource = document.createElement('div');
50 | divExampleCodeSource.innerHTML = document.getElementById('example-html-source').innerHTML;
51 | divExampleCodeSource.querySelectorAll('.clear-map-sandbox').forEach(map => map.innerHTML = '');
52 | indexHtmlContent = divExampleCodeSource.innerHTML;
53 |
54 | const indexHtml = `
55 |
56 |
57 |
58 | 0 0 1 0 2 0 1 1 0 1 3 1 3 2 0 2 4 2 4 3 0 3 5 3 5 4 0 4 6 4 7 5 8 5 9 5 8 5 7 5 10 5 11 6 12 6 13 6 12 7 11 7 14 7 15 8 16 8 17 8 16 8 15 8 18 8 19 9 20 9 21 9 20 10 19 10 22 10 23 11 24 11 25 11 24 12 23 12 26 12 27 13 28 13 29 13 28 14 27 14 30 14 31 15 32 15 33 15 32 15 31 15 34 15 35 16 36 16 37 16 36 16 35 16 38 16 38 17 35 17 39 17 38 18 39 18 40 18 38 19 41 19 36 19
98 |