当前位置:网站首页>Maptalks: basic operation and wms/wmts map service loading
Maptalks: basic operation and wms/wmts map service loading
2022-06-22 07:54:00 【I don't seem to know you】
maptalks Is a plug-in lightweight two-dimensional map rendering library , The core library contains the most commonly used core functions , Including base map rendering , Vector rendering , Built in interactive drawing tools , Ranging side tools, etc . For compatibility , The core library is mainly based on canvas Technical development ( The base map is in 3D mode webgl Rendering ).
For work , It took me half a day to have a rough look maptalks Official website Some examples of , Mainly map Map initialization and Layer Example of layer loading and management . Here is some sample code .
maptalks-Map initialization
Map: Map initialization
Map The example code for initialization is as follows , Reference resources API can Click here to view ,
// Create a base layer
let baseLayer = new maptalks.TileLayer('base', {
urlTemplate: 'https://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png',
subdomains: ['a', 'b', 'c', 'd'],
// attribution: '© <a href="http://osm.org">OpenStreetMap</a> contributors, © <a href="https://carto.com/">CARTO</a>',
// css filter
cssFilter: 'sepia(100%) invert(90%)',
opacity: 0.95, // TileLayer's opacity, 0-1
})
// initialization maptalks
var map = new maptalks.Map('map', {
center: [121.467, 31.0334],
zoom: 10,
minZoom: 1, // set map's min zoom to 14
maxZoom: 14, // set map's max zoom to 14
// Drag the tilt rotation parameter
//allow map to drag pitching, true by default
dragPitch: true, // Disable lifting / The camera pitch Angle switch
//allow map to drag rotating, true by default
dragRotate: true, //false- Disable rotation
//enable map to drag pitching and rotating at the same time, false by default
dragRotatePitch: true, //
doubleClickZoom: false, // Cancel the mouse double click zoom effect
baseLayer: baseLayer,
});

Map: Layer mount
To facilitate the management of various layer objects , It can be used as an attribute , Mount to the above created Map For instance .
// Mount layer
map.configLayers = {
base_layer: baseLayer, // Base map layer
sh_layer: undefined, // Base vector layer
shpt_layer: undefined, // Mark point layer
heatmap_layer: undefined, // Heat map layers
threejs_layer: undefined, //threejs Layers
//......
};
maptalks- load Geometry and Marker Marker points
Geometry Represent various geometric figures ,maptalks Includes Path、Marker、Label、Curve、Circle、Rectangle、Polygon And other geometric interfaces , Here is what will be JSON Data to Geometry, And then as a VectorLayer Vector layer objects , Load into Map In the map .
The sample code is as follows ,
/** * Acquisition data source - As geometry * */
function getDataAsGeometry(_dataSource) {
let geometries = undefined;
$.ajax({
url: "./data/" + _dataSource + ".json",
method: "GET",
async: false,
success: function(result, text, xhr) {
//GeoJSON utilities-Convert one or more GeoJSON objects to geometry
geometries = maptalks.GeoJSON.toGeometry(result);
}
});
return geometries;
}
/** * initialization JSON Boundary data * */
function intSHMap(_map, _layerName, _dataSource) {
// What you get is MultiPloygon Array
let geometries = getDataAsGeometry(_dataSource);
// Create a vector layer -VectorLayer
_map.configLayers[_layerName] =
/*let vecLayer =*/
new maptalks.VectorLayer('vector', geometries).addTo(_map);
// Set layer styles
_map.configLayers[_layerName].setStyle([{
visible: true,
// Style attribute
symbol: {
// Line style fill
lineColor: "skyblue",
lineWidth: 1,
// Face fill color settings
polygonFill: '#18f1f1',
polygonOpacity: 0,
}
}]);
}
/** * Initialize center mark point Marker * */
function initMarker(_map, _layerName, _dataSource) {
//json To geometry
let geometries = getDataAsGeometry(_dataSource);
let shptArray = new Array();
// Traverse geometries- Add center mark point
geometries.some(function(value, index, array) {
let properties = value.properties; // Get attribute data
shptArray.push(
new maptalks.Marker(properties.center, {
id: properties.name,
visible: true,
editable: true,
cursor: 'pointer',
shadowBlur: 0,
shadowColor: 'black',
draggable: false,
dragShadow: false, // display a shadow during dragging
drawOnAxis: null, // force dragging stick on a axis, can be: x, y
symbol: {
'textFaceName': 'sans-serif',
'textName': properties.name,
'textFill': '#fffff',
'textHorizontalAlignment': 'right',
'textSize': 22
},
properties: {
altitude: 2500,
properties: properties
}
})
// establish geometryCollection aggregate
let geometriesCollection = new maptalks.GeometryCollection(shptArray, {
})
// add to marker Assemble to VectorLayer in
_map.configLayers[_layerName] = new maptalks.VectorLayer('vector_Marker', geometriesCollection).addTo(_map);
}

maptalks Load map service
maptalks: load WMS Map service

adopt maptalks Load locally published geoserver-WMS The service example code is as follows ,( The above picture shows the preview layer )
/** * load WMS service * */
function loadWMSLayer(_map) {
var layer = new maptalks.WMSTileLayer('wms', {
'urlTemplate': 'http://localhost:8089/geoserver/shanyang/wms',
'crs': 'EPSG:3857',
'layers': 'shanyang:shanayng',
'styles': '',
'version': '1.1.1',
'format': 'image/png',
'transparent': true,
'uppercase': true
});
_map.addLayer(layer)
}
About loading parameters , You can get it from the address bar of the preview layer ,
The loading result is shown in the following figure ,
maptalks: load WMTS Map service

maptalks Loadable XYZ The standard WMTS Map tile slice data ( Slicing services are published in the form of static resources Tomcat Server , The directory structure is shown in the figure above ), The sample code is as follows ,
/** * load WMTS service */
function loadWMTSLayer(_map) {
let layer = new maptalks.TileLayer('boudaries', {
urlTemplate: 'http://localhost:8010/zaozhuang/zzt_tiles/' + '{z}/{x}/{y}.png',
minZoom: 0,
maxZoom: 16,
});
_map.addLayer(layer)
}
The loading results are as follows ,
边栏推荐
- LR 2022 ultra detailed installation tutorial "latest"
- Detailed explanation of subnet mask
- Asynchronous sending and receiving of message passing based concurrent programming (MPI)
- Model electricity experiment -- Experiment 1 transistor common emitter single transistor amplifier
- Phpcms mobile portal configuration
- Simplicity is the best method of network promotion
- 8、 Slider assembly
- Win openfeign from simple to deep
- Semaphore
- Docker install redis
猜你喜欢
![[普通物理]波的能量与干涉](/img/fe/066aa9e8ed776b8f069b59b7123367.png)
[普通物理]波的能量与干涉

(7)双向链表

Remote Desktop Manager

The significance of code coverage testing to programming white and its application

AutoCAD 2020.3 Chinese Version (old version)

Model electricity experiment -- Experiment 2 JFET common source amplifier circuit

Target detection series -- detailed explanation of RCNN principle

XMIND 2022 mind map active resources?

Upload your own library to pod

【宋红康 MySQL数据库 】【高级篇】【07】MySQL的存储引擎
随机推荐
Qualcomm platform LCM summary
Common array operations in JS
Fmdb usage details mark
Asynchronous sending and receiving of message passing based concurrent programming (MPI)
Do you want to modify the title of the website
ES6 set data type de duplication of array, intersection, union and difference
代码覆盖率测试对编程小白的意义及其使用方法
Use multithreading to speed up your crawler
Get through version 4.3 mind map
【图论常见模板题】4种最短路解法和2种最小生成树解法
各大企业连连出现亏损,环保行业何去何从?
itertools 排列组合
Charles uses
网站的排名对于网站很重要
5、 Image component
Unity AssetBundle packaging
Scrollrect rewrite recycle
[普通物理]波的能量与干涉
Crmeb mall order shipping function
FileTool