Skip to content

Commit 6c2eeaf

Browse files
committed
修改mapboxgl测量示例参数 reviewBy zhurc
1 parent c88471a commit 6c2eeaf

File tree

5 files changed

+43
-25
lines changed

5 files changed

+43
-25
lines changed

dist/iclient9-mapboxgl.js

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26604,7 +26604,7 @@ var MeasureService = function (_ServiceBase) {
2660426604
value: function _processParam(params) {
2660526605
if (params && !(params.geometry instanceof _SuperMap2.default.Geometry)) {
2660626606

26607-
params.geometry = _Util2.default.toSuperMapGeometry(params);
26607+
params.geometry = _Util2.default.toSuperMapGeometry(params.geometry);
2660826608
}
2660926609
return params;
2661026610
}
@@ -72261,8 +72261,6 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
7226172261
return 'jsonp_' + Date.now() + '_' + Math.ceil(Math.random() * 100000);
7226272262
}
7226372263

72264-
// Known issue: Will throw 'Uncaught ReferenceError: callback_*** is not defined'
72265-
// error if request timeout
7226672264
function clearFunction(functionName) {
7226772265
// IE8 throws an exception when you try to delete a property on window
7226872266
// http://stackoverflow.com/a/1824228/751089
@@ -72275,7 +72273,9 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
7227572273

7227672274
function removeScript(scriptId) {
7227772275
var script = document.getElementById(scriptId);
72278-
document.getElementsByTagName('head')[0].removeChild(script);
72276+
if (script) {
72277+
document.getElementsByTagName('head')[0].removeChild(script);
72278+
}
7227972279
}
7228072280

7228172281
function fetchJsonp(_url) {
@@ -72313,6 +72313,9 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
7231372313

7231472314
var jsonpScript = document.createElement('script');
7231572315
jsonpScript.setAttribute('src', '' + url + jsonpCallback + '=' + callbackFunction);
72316+
if (options.charset) {
72317+
jsonpScript.setAttribute('charset', options.charset);
72318+
}
7231672319
jsonpScript.id = scriptId;
7231772320
document.getElementsByTagName('head')[0].appendChild(jsonpScript);
7231872321

@@ -72321,7 +72324,19 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
7232172324

7232272325
clearFunction(callbackFunction);
7232372326
removeScript(scriptId);
72327+
window[callbackFunction] = function () {
72328+
clearFunction(callbackFunction);
72329+
};
7232472330
}, timeout);
72331+
72332+
// Caught if got 404/500
72333+
jsonpScript.onerror = function () {
72334+
reject(new Error('JSONP request to ' + _url + ' failed'));
72335+
72336+
clearFunction(callbackFunction);
72337+
removeScript(scriptId);
72338+
if (timeoutId) clearTimeout(timeoutId);
72339+
};
7232572340
});
7232672341
}
7232772342

dist/iclient9-mapboxgl.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/mapboxgl/01_measure_area.html

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,25 +50,27 @@
5050
trash: true
5151
}
5252
});
53-
map.addControl(draw,"top-left");
53+
map.addControl(draw, "top-left");
5454

55-
function updateArea(e) {
56-
var data= new SuperMap.MeasureParameters(draw.getAll());
57-
//获取当前画的图形的数据
58-
var current = data.geometry.features[data.geometry.features.length - 1];
59-
new mapboxgl.supermap.MeasureService(url).measureArea(current, function (serviceResult) {
60-
var area = serviceResult.result.area;
61-
var rounded_area = Math.round(area * 100) / 100;
62-
showAlert(rounded_area + "平方米");
63-
});
55+
function measureArea(e) {
56+
if (!e.features) {
57+
alert("没有获取到数据,请重新绘制");
58+
return;
59+
}
60+
var param = new SuperMap.MeasureParameters(e.features[0]);
61+
new mapboxgl.supermap.MeasureService(url).measureArea(param, function (serviceResult) {
62+
var area = serviceResult.result.area;
63+
var rounded_area = Math.round(area * 100) / 100;
64+
showAlert(rounded_area + "平方米");
65+
});
6466
}
6567

6668
function removeMsg() {
6769
$('#msg_container').remove();
6870
}
6971

70-
map.on('draw.create',updateArea);
71-
map.on('draw.delete',removeMsg);
72+
map.on('draw.create', measureArea);
73+
map.on('draw.delete', removeMsg);
7274

7375
function showAlert(msg) {
7476
var className = "alert-success";

examples/mapboxgl/01_measure_distance.html

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,13 @@
5454

5555
map.addControl(draw, "top-left");
5656

57-
function updateArea(e) {
58-
59-
var data= new SuperMap.MeasureParameters(draw.getAll());
60-
//获取当前画的图形的数据
61-
var current = data.geometry.features[data.geometry.features.length - 1];
62-
new mapboxgl.supermap.MeasureService(url).measureDistance(current, function (serviceResult) {
57+
function measureDistance(e) {
58+
if (!e.features) {
59+
alert("没有获取到数据,请重新绘制");
60+
return;
61+
}
62+
var param = new SuperMap.MeasureParameters(e.features[0]);
63+
new mapboxgl.supermap.MeasureService(url).measureDistance(param, function (serviceResult) {
6364
var distance = serviceResult.result.distance;
6465
showAlert(distance + "米");
6566
});
@@ -69,7 +70,7 @@
6970
$('#msg_container').remove();
7071
}
7172

72-
map.on('draw.create', updateArea);
73+
map.on('draw.create', measureDistance);
7374
map.on('draw.delete', removeMsg);
7475

7576
function showAlert(msg) {

src/mapboxgl/services/MeasureService.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export default class MeasureService extends ServiceBase {
6262
_processParam(params) {
6363
if (params && !(params.geometry instanceof SuperMap.Geometry)) {
6464

65-
params.geometry = Util.toSuperMapGeometry(params);
65+
params.geometry = Util.toSuperMapGeometry(params.geometry);
6666
}
6767
return params;
6868

0 commit comments

Comments
 (0)