var url = "http://192.168.0.65:8099/iserver/services/map-world/rest/maps/World";
var layer = new TileLayer({
source: new TileSuperMapRest({
url: url,
}),
projection: 'EPSG:4326'
})
var map = new Map({
target: 'map',
controls: ol.control.defaults({attributionOptions: {collapsed: false}}),
view: new View({
center: [-2.3294202469697893, 2.6155432633804367],
projection: 'EPSG:4326',
zoom: 3,
multiWorld: true,
}),
});
var source = new sourceVector({
wrapX: false,
});
var vectorLayer = new layerVector({
source: source,
style: new Style({
stroke: new Stroke({
color: 'rgb(255,0,0)',
width: 2
}),
fill: new Fill({
color: 'rgba(179,172,172,0.2)',
}),
})
});
map.addLayer(vectorLayer);
map.addControl(layer)
var drawPoint = new ol.interaction.Draw({
source: source,
type: "LineString"
});
var featurePoint;
var output = 0;
drawPoint.on('drawstart', function(evt) {
featurePoint = evt.feature;
});
drawPoint.on('drawend', function(evt) {
// 设置量算服务参数
var distanceMeasureParam = new MeasureParameters(featurePoint.getGeometry());
new ol.supermap.MeasureService(url,
{measureMode: ""}).measureDistance(distanceMeasureParam, function (serviceResult) {
alert(serviceResult.result.distance);
});
featurePoint.plotType = 'plotPoint';
featurePoint.setStyle(new Style({
text: new Text({
tAlign: 'center',
placement: 'line',
textBaseline: 'top',
offsetY: 5,
font: "12px 'Microsoft Yahei'",
text: output + "m",
fill: new Fill({
color: '#ff0000',
width: 2
}),
})
}));
});
map.addInteraction(drawPoint);