Skip to content

Commit

Permalink
tile array demos
Browse files Browse the repository at this point in the history
  • Loading branch information
deyihu committed Jan 20, 2025
1 parent ec79c07 commit f472bfd
Show file tree
Hide file tree
Showing 3 changed files with 274 additions and 0 deletions.
82 changes: 82 additions & 0 deletions demo/maxAvailableZoom-array.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<!DOCTYPE html>
<html>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>User Interactions - Draw tool to draw geometries</title>
<style type="text/css">
html,
body {
margin: 0px;
height: 100%;
width: 100%
}

.container {
width: 100%;
height: 100%
}
</style>
<link rel='stylesheet' href='https://cdn.jsdelivr.net/npm/maptalks/dist/maptalks.min.css' />
<script type='text/javascript' src='https://cdn.jsdelivr.net/npm/maptalks-gl/dist/maptalks-gl.js'></script>
<script type='text/javascript' src='https://unpkg.com/maptalks.tileclip@latest/dist/maptalks.tileclip.js'></script>

<body>
<div id="map" class="container"></div>
<script>

const tileActor = maptalks.getTileActor();
const maskId = '青浦区';
const roadTileUrl = 'https://wprd04.is.autonavi.com/appmaptile?x={x}&y={y}&z={z}&lang=zh_cn&size=1&scl=1&style=8&ltype=11';

const baseLayer = new maptalks.TileLayer('base', {
// debug: true,
urlTemplate: "https://webst01.is.autonavi.com/appmaptile?style=6&x={x}&y={y}&z={z}",
subdomains: ["a", "b", "c", "d"],
// bufferPixel: 1
})

baseLayer.on('renderercreate', function (e) {
//load tile image
// img(Image): an Image object
// url(String): the url of the tile
e.renderer.loadTileBitmap = function (url, tile, callback) {
const { x, y, z } = tile;
const urlTemplate = baseLayer.options.urlTemplate;
const maxAvailableZoom = 18;
tileActor.getTileWithMaxZoom({
x,
y,
z,
urlTemplate: [urlTemplate, roadTileUrl],
maxAvailableZoom,
// filter: 'sepia(100%) invert(90%)'
}).then(imagebitmap => {
callback(imagebitmap);
}).catch(error => {
//do some things
console.error(error);
})
};
});

var map = new maptalks.Map('map', {
zoomControl: true,
"center": [121.65586045, 31.12453538], "zoom": 18.064897200334302, "pitch": 0, "bearing": 0,
});

const sceneConfig = {
postProcess: {
enable: true,
antialias: { enable: true }
}
};
const groupLayer = new maptalks.GroupGLLayer('group', [], { sceneConfig });
groupLayer.addTo(map);

baseLayer.addTo(groupLayer);


</script>
</body>

</html>
115 changes: 115 additions & 0 deletions demo/maxAvailableZoom-polygon-clip-array.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
<!DOCTYPE html>
<html>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>User Interactions - Draw tool to draw geometries</title>
<style type="text/css">
html,
body {
margin: 0px;
height: 100%;
width: 100%
}

.container {
width: 100%;
height: 100%
}
</style>
<link rel='stylesheet' href='https://cdn.jsdelivr.net/npm/maptalks/dist/maptalks.min.css' />
<script type='text/javascript' src='https://cdn.jsdelivr.net/npm/maptalks-gl/dist/maptalks-gl.js'></script>
<script type='text/javascript' src='https://unpkg.com/maptalks.tileclip@latest/dist/maptalks.tileclip.js'></script>

<body>
<div id="map" class="container"></div>
<script>

const tileActor = maptalks.getTileActor();
const maskId = '青浦区';
const roadTileUrl = 'https://wprd04.is.autonavi.com/appmaptile?x={x}&y={y}&z={z}&lang=zh_cn&size=1&scl=1&style=8&ltype=11';
const baseLayer = new maptalks.TileLayer('base', {
// debug: true,
urlTemplate: "https://webst01.is.autonavi.com/appmaptile?style=6&x={x}&y={y}&z={z}",
subdomains: ["a", "b", "c", "d"],
// bufferPixel: 1
})

baseLayer.on('renderercreate', function (e) {
//load tile image
// img(Image): an Image object
// url(String): the url of the tile
e.renderer.loadTileBitmap = function (url, tile, callback) {
const { x, y, z } = tile;
const urlTemplate = baseLayer.options.urlTemplate;
const maxAvailableZoom = 18;
tileActor.getTileWithMaxZoom({
x,
y,
z,
urlTemplate: [urlTemplate, roadTileUrl],
maxAvailableZoom,
// filter: 'sepia(100%) invert(90%)'
}).then(imagebitmap => {
tileActor.clipTile({
tile: imagebitmap,
tileBBOX: baseLayer._getTileBBox(tile),
projection: baseLayer.getProjection().code,
tileSize: baseLayer.getTileSize().width,
maskId,
}).then(image => {
callback(image);
}).catch(error => {
//do some things
console.error(error);
})
}).catch(error => {
//do some things
console.error(error);
})
};
});

var map = new maptalks.Map('map', {
zoomControl: true,
"center": [121.65586045, 31.12453538], "zoom": 9.064897200334302, "pitch": 0, "bearing": 0,
});

const sceneConfig = {
postProcess: {
enable: true,
antialias: { enable: true }
}
};
const groupLayer = new maptalks.GroupGLLayer('group', [], { sceneConfig });
groupLayer.addTo(map);

const layer = new maptalks.VectorLayer('layer').addTo(map);

const symbol = {
polygonOpacity: 0,
lineColor: 'red'
}


// baseLayer.addTo(groupLayer);

fetch('./青浦区-holes.geojson').then(res => res.json()).then(geojson => {
const polygons = maptalks.GeoJSON.toGeometry(geojson, (geo => {
geo.setSymbol(symbol);
}));
layer.addGeometry(polygons);
map.setView({
"center":[120.9813688,31.06587294],"zoom":19.516412543204773,"pitch":0,"bearing":0
})
tileActor.injectMask(maskId, geojson.features[0]).then(data => {
baseLayer.addTo(groupLayer);
}).catch(error => {
console.error(error);
})
})


</script>
</body>

</html>
77 changes: 77 additions & 0 deletions demo/tile-array.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<!DOCTYPE html>
<html>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>User Interactions - Draw tool to draw geometries</title>
<style type="text/css">
html,
body {
margin: 0px;
height: 100%;
width: 100%
}

.container {
width: 100%;
height: 100%
}
</style>
<link rel='stylesheet' href='https://cdn.jsdelivr.net/npm/maptalks/dist/maptalks.min.css' />
<script type='text/javascript' src='https://cdn.jsdelivr.net/npm/maptalks-gl/dist/maptalks-gl.js'></script>
<script type='text/javascript' src='https://unpkg.com/maptalks.tileclip@latest/dist/maptalks.tileclip.js'></script>
<body>
<div id="map" class="container"></div>
<script>

const tileActor = maptalks.getTileActor();
const maskId = '青浦区';

const roadTileUrl = 'https://wprd04.is.autonavi.com/appmaptile?x={x}&y={y}&z={z}&lang=zh_cn&size=1&scl=1&style=8&ltype=11';

const baseLayer = new maptalks.TileLayer('base', {
// debug: true,
urlTemplate: "https://webst01.is.autonavi.com/appmaptile?style=6&x={x}&y={y}&z={z}",
subdomains: ["a", "b", "c", "d"],
// bufferPixel: 1
})

baseLayer.on('renderercreate', function (e) {
//load tile image
// img(Image): an Image object
// url(String): the url of the tile
e.renderer.loadTileBitmap = function (url, tile, callback) {
const { x, y, z } = tile;
const url1 = roadTileUrl.replace("{x}", x).replace('{y}', y).replace('{z}', z);
tileActor.getTile({
url: [url, url1].map(url => {
return maptalks.Util.getAbsoluteURL(url)
})
}).then(imagebitmap => {
callback(imagebitmap);
}).catch(error => {
//do some things
console.error(error);
})
};
});

var map = new maptalks.Map('map', {
"center": [121.65586045, 31.12453538], "zoom": 9.064897200334302, "pitch": 0, "bearing": 0,
});

const sceneConfig = {
postProcess: {
enable: true,
antialias: { enable: true }
}
};
const groupLayer = new maptalks.GroupGLLayer('group', [], { sceneConfig });
groupLayer.addTo(map);

baseLayer.addTo(groupLayer);


</script>
</body>

</html>

0 comments on commit f472bfd

Please sign in to comment.