npm install leaflet
import L from "leaflet";
import "leaflet/dist/leaflet.css";
<div id="map"></div>
created() {
let _that = this;
_that.normal = new L.layerGroup();
_that.factoryLandPolygon = new L.layerGroup();
_that.activePolygon = new L.layerGroup();
},
loadgraymapnew() {
let _that = this;
let southWest = [29.1304, 118.1217];
let northEast = [30.6191, 120.7753];
let bounds = L.latLngBounds(southWest, northEast);
let a = "http://t4.tianditu.gov.cn/DataServer?T=ter_c&x={x}&y={y}&l={z}&tk="
let b = "http://t4.tianditu.gov.cn/DataServer?T=vec_c&x={x}&y={y}&l={z}&tk="
let c =
"http://t4.tianditu.gov.cn/DataServer?T=img_c&x={x}&y={y}&l={z}&tk="
let d = "http://t4.tianditu.gov.cn/DataServer?T=cia_c&x={x}&y={y}&l={z}&tk="
let e = "http://t4.tianditu.gov.cn/DataServer?T=cta_c&x={x}&y={y}&l={z}&tk="
let f = "http://t4.tianditu.gov.cn/DataServer?T=cva_c&x={x}&y={y}&l={z}&tk="
let normalm = L.tileLayer.chinaProvider("TianDiTu.Normal.Map", {
maxZoom: 18,
minZoom: 5,
key: _that.mapKey,
}),
normala = L.tileLayer.chinaProvider("TianDiTu.Normal.Annotion", {
maxZoom: 18,
minZoom: 5,
key: _that.mapKey,
}),
imgm = L.tileLayer.chinaProvider("TianDiTu.Satellite.Map", {
maxZoom: 18,
minZoom: 5,
key: _that.mapKey,
}),
imga = L.tileLayer.chinaProvider("TianDiTu.Satellite.Annotion", {
maxZoom: 18,
minZoom: 5,
key: _that.mapKey,
});
let normal = L.layerGroup([normalm, normala]);
let image = L.layerGroup([imgm, imga]);
_that.normal = normal
_that.image = image
let baseLayers = {
地图: normal,
影像: image
};
const ret = new L.Proj.CRS("EPSG:4490", "+proj=longlat +ellps=GRS80 +no_defs", {
resolutions: [
1.40625,
0.703125,
0.3515625,
0.17578125,
0.087890625,
0.0439453125,
0.02197265625,
0.010986328125,
0.0054931640625,
0.00274658203125,
0.001373291015625,
0.0006866455078125,
0.00034332275390625,
0.000171661376953125,
8.58306884765625e-5,
4.29153442382813e-5,
2.14576721191406e-5,
1.07288360595703e-5,
5.36441802978516e-6,
2.68220901489258e-6,
1.34110450744629e-6,
],
origin: [-180, 90]
});
_that.map = L.map("map", {
center: [31.59, 120.29],
zoom: 12,
maxZoom: 18,
minZoom: 5,
layers: [normal],
zoomControl: false
});
L.control.scale({
maxWidth: 200,
metric: true,
imperial: false
}).addTo(_that.map);
_that.map.setView([30.3, 120.1769], 12);
_that.factoryLandPolygon = esri.dynamicMapLayer({
url: 'https://************/arcgis/rest/services/KGDK/MapServer',
opacity: .6,
useCors: true,
maxZoom: 20,
minZoom: 9,
})
this.map.addLayer(_that.factoryLandPolygon);
_that.factoryLandPolygon.bindPopup(
function(err, featureCollection, response) {
_that.initPolygons(response.results[0], _that.factoryLandPolygon)
_that.strings(JSON.stringify(response.results[0]))
_that.actualityshow = true
});
},
initPolygons(aData, aDataScore) {
console.log(aData);
console.log(aDataScore)
let self = this;
let featureCollection = aData;
let coor = featureCollection.geometry.rings;
let item = featureCollection;
let position = coor[0][0];
let endPosition = coor[0][0];
if (coor.length > 1) {
position = coor[0][0][0];
endPosition = coor[0][0][parseInt(coor[0][0].length / 2)];
} else {
if (parseInt(coor[0].length / 2) > 1) {
endPosition = coor[0][parseInt(coor[0].length / 2)];
}
}
let plang = self.revert(coor)
let polygon = L.polygon(plang, {
color: 'red',
weight: 2,
fillColor: "#000000",
fillOpacity: 0
});
polygon.addTo(self.activePolygon);
self.map.addLayer(self.activePolygon)
self.map.setView([centerPoint[1], centerPoint[0]], 15);
},
revert(points) {
var latlogs = [];
for (var i = 0; i < points.length; i++) {
var p = points[i];
var path = [];
for (var j = 0; j < p.length; j++) {
if (p[j].length <= 2) {
path.push([p[j][1], p[j][0]]);
} else {
for (var l = 0; l < p[j].length; l++) {
if (Object.prototype.toString.call(p[j][l]) == "[object Array]") {
path.push([p[j][l][1], p[j][l][0]]);
} else {
path.push([p[j][1], p[j][0]]);
}
}
}
}
latlogs.push(path);
}
return latlogs;
},
addZoom(zoom) {
let _that = this;
_that.map.zoomIn();
},
subtractZoom(zoom) {
let _that = this;
_that.map.zoomOut();
},
_that.map.removeLayer(_that.activePolygon);
_that.map.removeLayer(_that.activePolygon);
_that.activePolygon = new L.layerGroup();
HTML
<el-drawer :visible.sync="drawer" id="swMap" :modal="false">
<div class="demo-image__placeholder">
<div class="block" :class="isactive == 'normal' ? 'active' : ''" @click="isyput()">
<el-image class="imgSize" :src="mapType.nMap"></el-image>
<span class="demonstration">标准地图</span>
</div>
<div class="block" :class="isactive == 'image' ? 'active' : ''" @click="isyingx()">
<el-image class="imgSize" :src="mapType.iMap"></el-image>
<span class="demonstration">影像地图</span>
</div>
</div>
</el-drawer>
fun(){
let normalm = L.tileLayer.chinaProvider("TianDiTu.Normal.Map", {
maxZoom: 18,
minZoom: 5,
key: _that.mapKey,
}),
normala = L.tileLayer.chinaProvider("TianDiTu.Normal.Annotion", {
maxZoom: 18,
minZoom: 5,
key: _that.mapKey,
}),
imgm = L.tileLayer.chinaProvider("TianDiTu.Satellite.Map", {
maxZoom: 18,
minZoom: 5,
key: _that.mapKey,
}),
imga = L.tileLayer.chinaProvider("TianDiTu.Satellite.Annotion", {
maxZoom: 18,
minZoom: 5,
key: _that.mapKey,
});
let normal = L.layerGroup([normalm, normala]);
let image = L.layerGroup([imgm, imga]);
_that.normal = normal
_that.image = image
}
isyingx() {
this.map.removeLayer(this.image)
this.map.addLayer(this.image);
},
isyput() {
this.map.removeLayer(this.normal)
this.map.addLayer(this.normal);
},