Skip to content

Commit

Permalink
reserve merge conflict over road casing order #42
Browse files Browse the repository at this point in the history
  • Loading branch information
nvkelso committed Jul 12, 2023
2 parents 90f584b + c7aab17 commit 49e81d4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 54 deletions.
56 changes: 3 additions & 53 deletions openlayers.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
<meta charset="utf-8"/>
<script src="https://cdn.jsdelivr.net/npm/ol@v7.3.0/dist/ol.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/ol@v7.3.0/ol.css">
<script src="https://unpkg.com/pmtiles@2.7.2/dist/index.js"></script>
<script src="https://unpkg.com/protomaps-themes-base@1.3.0/dist/index.js"></script>
<script src="https://cdn.jsdelivr.net/npm/ol-mapbox-style@v10.5.0/dist/olms.js"></script>
<script src="https://unpkg.com/ol-pmtiles@0.1.0/dist/olpmtiles.js"></script>
<style>
body, #map {
height:100vh;
Expand All @@ -17,60 +17,10 @@
<body>
<div id="map"></div>
<script type="text/javascript">
class VectorPMTilesSource extends ol.source.VectorTile {
tileLoadFunction = (tile,url) => {
// the URL construction is done internally by OL, so we need to parse it
// back out here using a hacky regex
const re = new RegExp(/pmtiles:\/\/(.+)\/(\d+)\/(\d+)\/(\d+)/);
const result = url.match(re);
const z = +result[2];
const x = +result[3];
const y = +result[4];

tile.setLoader((extent, resolution, projection) => {
tile.setState(1); // LOADING
this._p.getZxy(z,x,y).then((tile_result) => {
if (tile_result) {
const format = tile.getFormat();
const features = format.readFeatures(tile_result.data.buffer, {
extent: extent,
featureProjection: projection
});
tile.setFeatures(features);
tile.setState(2); // LOADED
} else {
tile.setFeatures([]);
tile.setState(4); // EMPTY
}
});
});
}

constructor(options) {
super({
state:"loading",
url: "pmtiles://" + options.url + "/{z}/{x}/{y}",
format: new ol.format.MVT(),
attributions: options.attributions
});

this._p = new pmtiles.PMTiles(options.url);
this._p.getHeader().then(h => {
if (h.tileType !== pmtiles.TileType.Mvt) {
console.warn("Warning: pmtiles tile type is not mvt");
}
this.tileGrid.minZoom = h.minZoom;
this.tileGrid.maxZoom = h.maxZoom;
this.setTileLoadFunction(this.tileLoadFunction);
this.setState("ready");
});
}
}

const baseLayer = new ol.layer.VectorTile({
declutter: true,
source: new VectorPMTilesSource({
url: "https://r2-public.protomaps.com/protomaps-sample-datasets/protomaps_vector_planet_odbl_z10.pmtiles",
source: new olpmtiles.PMTilesVectorSource({
url: "https://r2-public.protomaps.com/protomaps-sample-datasets/protomaps-basemap-opensource-20230408.pmtiles",
attributions: ["© OpenStreetMap"]
}),
style: null
Expand Down
8 changes: 8 additions & 0 deletions tiles/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
root = true

[*]
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = space
indent_size = 2
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public void processFeature(SourceFeature sf, FeatureCollector features) {

if (sf.hasTag("highway", "motorway_link", "trunk_link", "primary_link", "secondary_link",
"tertiary_link")) {
feat.setAttr("pmap:link", 1).setZoomRange(12, 15);
feat.setAttr("pmap:link", 1);
}

// Set "brunnel" (bridge / tunnel) property where "level" = 1 is a bridge, 0 is ground level, and -1 is a tunnel
Expand Down

0 comments on commit 49e81d4

Please sign in to comment.