westdc-zf1/htdocs/static-sanjy-np/js/map.js

244 lines
6.5 KiB
JavaScript
Raw Normal View History

2018-06-23 15:23:07 +00:00
var center = [10599381.969998538, 4091531.57875448];
2018-07-18 09:56:59 +00:00
var WESTDC_MAP_SERVER = "http://210.77.79.190:8888/geoserver";
2018-06-23 07:53:34 +00:00
2018-06-23 15:23:07 +00:00
// $(document).ready(function(){
// $('#map').height($(window).height() - $('.pageTitle').height() - $('.header').height());
// });
2018-06-23 07:53:34 +00:00
var view = new ol.View({
projection: 'EPSG:3857',
center: center,
loadTilesWhileAnimating: true,
zoom: 7
});
var map = new ol.Map({
target: 'map',
layers: [
// new ol.layer.Tile({
// title: "天地图卫星影像",
// source: new ol.source.XYZ({
// url: 'http://t3.tianditu.com/DataServer?T=img_w&x={x}&y={y}&l={z}'
// }),
// visible: true
// }),
new ol.layer.Tile({
title: "天地图底图",
source: new ol.source.XYZ({
url: 'http://t0.tianditu.com/DataServer?T=vec_w&x={x}&y={y}&l={z}'
}),
visible: true
}),
new ol.layer.Tile({
title: "天地图标注",
source: new ol.source.XYZ({
url: 'http://t3.tianditu.com/DataServer?T=cva_w&x={x}&y={y}&l={z}'
}),
visible: true
})
],
controls: [],
view: view
});
//http://t3.tianditu.com/DataServer?T=img_w&x={x}&y={y}&l={z}
map.on('click', function(event) {
console.log(event.coordinate)
});
2018-07-18 09:56:59 +00:00
function WMSLayer(layer){
return new ol.layer.Tile({
source: new ol.source.TileWMS({
url: WESTDC_MAP_SERVER + '/sjynp/wms',
params: {'FORMAT': 'image/png',
'VERSION': '1.1.1',
tiled: true,
STYLES: '',
LAYERS: 'sjynp:' + layer,
tilesOrigin: 9951420.669071037 + "," + 3974091.390929395
}
}),
opacity: 0.7,
visible: true
})
}
2018-06-23 07:53:34 +00:00
var layers = {
"boundYellowRiver": {
title: "黄河园区",
2018-06-24 10:37:35 +00:00
showTitle: false,
2018-07-18 09:56:59 +00:00
layer: WMSLayer('yellow_river_park'),
2018-06-23 15:23:07 +00:00
center: [10879848.96087429, 4117877.9384883614],
zoom: 8
2018-06-23 07:53:34 +00:00
},
"boundLanCangJiang": {
title: "澜沧江园区",
2018-06-24 10:37:35 +00:00
showTitle: false,
2018-07-18 09:56:59 +00:00
layer: WMSLayer('lancang_river_park'),
2018-06-23 15:23:07 +00:00
center: [10557705.50270024, 3935037.30807186],
zoom: 8
2018-06-23 07:53:34 +00:00
},
"boundChangjiang": {
title: "长江园区",
2018-06-24 10:37:35 +00:00
showTitle: false,
2018-07-18 09:56:59 +00:00
layer: WMSLayer('yangtze_river_park'),
2018-06-23 15:23:07 +00:00
center: [10451297.903618347, 4131586.2994088964],
zoom: 7
2018-06-23 07:53:34 +00:00
},
2018-07-18 09:56:59 +00:00
"boundArea": {
title: "县区边界",
layer: WMSLayer('county_bound_sanjiangyuan'),
2018-06-24 12:09:03 +00:00
center: [10669314.496444024, 4028957.542397498],
zoom: 6
},
2018-07-18 09:56:59 +00:00
"boundZhiduo": {
title: "治多县",
layer: WMSLayer('county_bound_zhiduo'),
center: [10755941.536062466, 3865974.688836431],
zoom: 6
},
"boundMaduo": {
title: "玛多县",
layer: WMSLayer('county_bound_maduo'),
center: [10669314.496444024, 4028957.542397498],
zoom: 6
},
"boundZaduo": {
title: "杂多县",
layer: WMSLayer('county_bound_zaduo'),
2018-06-24 12:09:03 +00:00
center: [10669314.496444024, 4028957.542397498],
zoom: 6
2018-06-24 10:37:35 +00:00
},
2018-07-18 09:56:59 +00:00
"boundQumalai": {
title: "曲麻莱县",
layer: WMSLayer('county_bound_qumalai'),
center: [10669314.496444024, 4028957.542397498],
zoom: 6
},
"sanjiangyuanFunctionArea": {
title: "三江源功能分区",
layer: WMSLayer('sanjiangyuan_national_nature_reserve'),
center: [10669314.496444024, 4028957.542397498],
zoom: 7
},
"hohxiFunctionArea": {
title: "可可西里功能分区",
layer: WMSLayer('hohxi_national_nature_reserve'),
center: [10194893.748449273, 4212372.969082045],
zoom: 8
}
2018-06-23 07:53:34 +00:00
};
2018-06-23 15:23:07 +00:00
function flyTo(location, zoom, duration, done) {
if(!duration) duration = 2000;
if(!zoom) zoom = 8;
2018-06-23 07:53:34 +00:00
var parts = 2;
var called = false;
function callback(complete) {
--parts;
if (called) {
return;
}
if (parts === 0 || !complete) {
called = true;
done(complete);
}
}
view.animate({
center: location,
duration: duration
}, callback);
view.animate({
zoom: 7,
duration: duration / 2
}, {
zoom: zoom,
duration: duration / 2
}, callback);
}
2018-06-23 15:23:07 +00:00
function pointTextStyle(text, size, color) {
return new ol.style.Style({
text: new ol.style.Text({
font: 'bold '+size+'px "Open Sans", "Arial Unicode MS", "sans-serif"',
overflow: false,
fill: new ol.style.Fill({
color: color
}),
text: text
})
})
}
function addTextMarker(text, location){
return new ol.layer.Vector({
source: new ol.source.Vector({
features: [new ol.Feature({
geometry: new ol.geom.Point(location)
})]
}),
style: pointTextStyle(text, 18, "#246166")
});
}
var textLayers = {};
2018-06-23 07:53:34 +00:00
$('#map-layers').click(function(){
$('#layers-selector').toggle();
});
$('.layer-toggle-btn').click(function(){
$('#layers-selector').toggle();
var layerId = $(this).data('layer');
2018-06-23 15:23:07 +00:00
var currentLayer = layers[layerId];
2018-06-23 07:53:34 +00:00
if (this.checked === false) {
2018-06-23 15:23:07 +00:00
map.removeLayer(currentLayer.layer);
map.removeLayer(textLayers[currentLayer.title]);
2018-06-23 07:53:34 +00:00
} else {
2018-06-23 15:23:07 +00:00
map.addLayer(currentLayer.layer);
2018-06-23 07:53:34 +00:00
// view.setCenter(layers[layerId].center);
2018-06-23 15:23:07 +00:00
flyTo(currentLayer.center, currentLayer.zoom, 2000, function(){
2018-06-24 10:37:35 +00:00
if(currentLayer.showTitle)
{
textLayers[currentLayer.title] = addTextMarker(currentLayer.title, currentLayer.center);
map.addLayer(textLayers[currentLayer.title]);
}
2018-06-23 07:53:34 +00:00
});
}
2018-06-23 15:23:07 +00:00
});
$('#zoom-in').click(function(){
if(view.getZoom() >=20)
view.setZoom(20);
else
view.setZoom(view.getZoom() + 1);
});
$('#zoom-out').click(function(){
if(view.getZoom() <=6)
view.setZoom(6);
else
view.setZoom(view.getZoom() - 1);
});
$('#btn-back-to-sjy').click(function(){
flyTo(center, 7, 2000, function(){
});
2018-06-23 15:27:24 +00:00
});
2018-06-24 06:24:22 +00:00
$('#btn-close-layers').click(function(){
for(var i in layers){
map.removeLayer(layers[i].layer);
if(textLayers[layers[i].title])
map.removeLayer(textLayers[layers[i].title]);
}
2018-06-24 12:09:03 +00:00
$('.layer-toggle-btn').attr('checked', false);
flyTo(center, 7, 2000, function(){});
2018-06-24 06:24:22 +00:00
});
2018-06-23 15:27:24 +00:00
$('#layers-selector').show();