Skip to content

Commit bdda6b8

Browse files
committed
Website updates
1 parent 2fabb1e commit bdda6b8

File tree

9 files changed

+48
-110
lines changed

9 files changed

+48
-110
lines changed

dist/en/main/examples/common.js

Lines changed: 24 additions & 74 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/en/main/examples/common.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/en/main/examples/drag-and-drop-custom-kmz.html

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -143,14 +143,13 @@ <h5 class="modal-title" id="tag-example-title"></h5>
143143

144144
<div class="row-fluid">
145145
<p id="shortdesc">Example of using the drag-and-drop interaction with a custom format to handle KMZ files.</p>
146-
<div id="docs"><p>Example of using the drag-and-drop interaction with a custom format to handle KMZ files. In addition to the formats used in the <a href="drag-and-drop.html">Drag-and-Drop</a> example a custom format (subclassing KML) is used to handle KMZ files. KML and icons must be extracted from the KMZ array buffer synchronously. <a href="https://stuk.github.io/jszip/documentation/upgrade_guide.html" target="_blank">JSZip 2.x</a> is used as it has better browser compatibility and is simpler to code than the more recent <a href="https://github.com/ericvergnaud/jszip#readme" target="_blank">JSZip-sync</a>. There is no projection transform support, so this will only work with data in EPSG:4326 and EPSG:3857.</p>
146+
<div id="docs"><p>Example of using the drag-and-drop interaction with a custom format to handle KMZ files. In addition to the formats used in the <a href="drag-and-drop.html">Drag-and-Drop</a> example a custom format (subclassing KML) is used to handle KMZ files. KML and icons must be extracted from the KMZ array buffer synchronously. There is no projection transform support, so this will only work with data in EPSG:4326 and EPSG:3857.</p>
147147
</div>
148148
</div>
149149

150150
<div class="row-fluid">
151151
<h5 class="source-heading">main.js</h5>
152-
<pre><code id="example-js-source" class="language-js">import JSZip from &#x27;jszip&#x27;;
153-
import Map from &#x27;ol/Map.js&#x27;;
152+
<pre><code id="example-js-source" class="language-js">import Map from &#x27;ol/Map.js&#x27;;
154153
import View from &#x27;ol/View.js&#x27;;
155154
import {
156155
DragAndDrop,
@@ -159,31 +158,32 @@ <h5 class="source-heading">main.js</h5>
159158
import {GPX, GeoJSON, IGC, KML, TopoJSON} from &#x27;ol/format.js&#x27;;
160159
import {OSM, Vector as VectorSource} from &#x27;ol/source.js&#x27;;
161160
import {Tile as TileLayer, Vector as VectorLayer} from &#x27;ol/layer.js&#x27;;
161+
import {unzipSync} from &#x27;fflate&#x27;;
162162

163163
// Create functions to extract KML and icons from KMZ array buffer,
164164
// which must be done synchronously.
165165

166-
const zip &#x3D; new JSZip();
166+
let zip;
167167

168168
function getKMLData(buffer) {
169-
let kmlData;
170-
zip.load(buffer);
171-
const kmlFile &#x3D; zip.file(/\.kml$/i)[0];
172-
if (kmlFile) {
173-
kmlData &#x3D; kmlFile.asText();
169+
zip &#x3D; unzipSync(new Uint8Array(buffer));
170+
const kml &#x3D; Object.keys(zip).find((key) &#x3D;&gt; /\.kml$/i.test(key));
171+
if (!(kml in zip)) {
172+
return null;
174173
}
175-
return kmlData;
174+
return new TextDecoder().decode(zip[kml]);
176175
}
177176

178177
function getKMLImage(href) {
179178
const index &#x3D; window.location.href.lastIndexOf(&#x27;/&#x27;);
180-
if (index !&#x3D;&#x3D; -1) {
181-
const kmlFile &#x3D; zip.file(href.slice(index + 1));
182-
if (kmlFile) {
183-
return URL.createObjectURL(new Blob([kmlFile.asArrayBuffer()]));
184-
}
179+
if (index &#x3D;&#x3D;&#x3D; -1) {
180+
return href;
181+
}
182+
const image &#x3D; href.slice(index + 1);
183+
if (!(image in zip)) {
184+
return href;
185185
}
186-
return href;
186+
return URL.createObjectURL(new Blob([zip[image]]));
187187
}
188188

189189
// Define a KMZ format class by subclassing ol/format/KML
@@ -338,7 +338,7 @@ <h5 class="source-heading">package.json</h5>
338338
&quot;name&quot;: &quot;drag-and-drop-custom-kmz&quot;,
339339
&quot;dependencies&quot;: {
340340
&quot;ol&quot;: &quot;10.2.2-dev&quot;,
341-
&quot;jszip&quot;: &quot;^3.8.0&quot;
341+
&quot;fflate&quot;: &quot;^0.8.2&quot;
342342
},
343343
&quot;devDependencies&quot;: {
344344
&quot;vite&quot;: &quot;^3.2.3&quot;

dist/en/main/examples/drag-and-drop-custom-kmz.js

Lines changed: 1 addition & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/en/main/examples/drag-and-drop-custom-kmz.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/en/main/examples/export-pdf.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/en/main/examples/export-pdf.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/en/main/examples/print-to-scale.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/en/main/examples/print-to-scale.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)