console
const country = new ol.style.Style({
stroke: new ol.style.Stroke({
color: 'gray',
width: 1,
}),
fill: new ol.style.Fill({
color: 'rgba(20,20,20,0)',
}),
});
const selectedCountry = new ol.style.Style({
stroke: new ol.style.Stroke({
color: 'rgba(200,20,20,0.8)',
width: 2,
}),
fill: new ol.style.Fill({
color: 'rgba(200,20,20,0.4)',
}),
});
const selectedCountry1 = new ol.style.Style({
stroke: new ol.style.Stroke({
color: 'rgba(20,210,20,0.8)',
width: 2,
}),
fill: new ol.style.Fill({
color: 'rgba(20,202,20,0.4)',
}),
});
const selectedCountry2 = new ol.style.Style({
stroke: new ol.style.Stroke({
color: 'rgba(205,200,20,0.8)',
width: 2,
}),
fill: new ol.style.Fill({
color: 'rgba(205,200,20,0.4)',
}),
});
let selection = {
"河北省": selectedCountry,
"山东省": selectedCountry1,
"山西省": selectedCountry2,
};
var vectorLayer1 = new ol.layer.VectorTile({
source: new ol.source.VectorTile({
format: new ol.format.MVT(),
url: "https://tiles.kye-erp.com/maptile-dispatch/data/kye_admin_pro/{z}/{x}/{y}.pbf"
}),
style: country
})
var map = new ol.Map({
target: 'map',
layers: [
vectorLayer1
],
view: new ol.View({
center: [0, 0],
zoom: 2,
multiWorld: true,
})
});
const selectionLayer = new ol.layer.VectorTile({
map: map,
renderMode: 'vector',
source: vectorLayer1.getSource(),
style: function (feature) {
if (feature.getProperties().admin_name in selection) {
return selection[feature.getProperties().admin_name];
}
},
});
map.on(['click'], function (event) {
console.info(vectorLayer1)
vectorLayer1.getFeatures(event.pixel).then(function (features) {
console.info(features)
if (!features.length) {
selection = {};
selectionLayer.changed();
return;
}
const feature = features[0];
if (!feature) {
return;
}
const fid = feature.getId();
if (selectElement.value.indexOf('singleselect') === 0) {
selection = {};
}
selection[fid] = feature;
selectionLayer.changed();
});
});
<div id="map" class="map"></div>
.map {
height: 600px;
width: 100%;
}