var map, interaction, vectorLayer, feature,
url = (window.isLocal ? window.server : "http://support.supermap.com.cn:8090") + "/iserver/services/map-world/rest/maps/World";
//初始化地图
var map = new ol.Map({
target: 'map',
controls: ol.control.defaults({
attributionOptions: {
collapsed: false
}
})
.extend([new ol.supermap.control.Logo()]),
view: new ol.View({
center: [12911600, 4359823],
minZoom: 3,
zoom: 12,
})
});
var layer = new ol.layer.Tile({
source: new ol.source.SuperMapCloud()
});
map.addLayer(layer);
//-----------------------------------------------------------
//地图比例尺
var zoomControl = new ol.control.ScaleLine();
map.addControl(zoomControl);
//--------------------------------------------------
$('#measure_distance').click((function() {
var source = new ol.source.Vector({ wrapX: false });
vectorLayer = new ol.layer.Vector({
source: source
});
map.addLayer(vectorLayer);
var interaction = new ol.interaction.Draw({
source: source,
type: "LineString"
});
interaction.on('drawstart', function(evt) {
feature = evt.feature;
});
interaction.on('drawend', function() {
var distanceMeasureParam = new SuperMap.MeasureParameters(feature.getGeometry());
new ol.supermap.MeasureService(url, { measureMode: "" }).measureDistance(distanceMeasureParam, function(serviceResult) {
alert(serviceResult.result.distance , true);
});
});
map.addInteraction(interaction);
}));