|
7 | 7 | <script type="text/javascript" src="http://cdn.leafletjs.com/leaflet/v1.0.2/leaflet.js"></script> |
8 | 8 | <script type="text/javascript" src="../../dist/SuperMapiClient9 for Leaflet.js"></script> |
9 | 9 | <script type="text/javascript"> |
10 | | - var map, marker, featureGroup, is, resultLayer, |
| 10 | + var map, marker, featureGroup, id, resultLayer, |
11 | 11 | baseUrl = "http://support.supermap.com.cn:8090/iserver/services/map-world/rest/maps/World", |
12 | 12 | urlCapital = "http://support.supermap.com.cn:8090/iserver/services/data-world/rest/data/datasources/World/datasets/Capitals", |
13 | 13 | url = "http://support.supermap.com.cn:8090/iserver/services/data-world/rest/data"; |
|
19 | 19 | maxZoom: 18, |
20 | 20 | zoom: 3 |
21 | 21 | }); |
22 | | - L.supermap.tiledMapLayer(baseUrl,{projection:"4326"}).addTo(map); |
| 22 | + L.supermap.tiledMapLayer(baseUrl).addTo(map); |
23 | 23 | featureGroup = L.featureGroup().addTo(map); |
24 | | - marker = L.circleMarker([34, 108], {color: "red"}); |
25 | 24 | initFeature(); |
26 | 25 | } |
27 | 26 | function initFeature() { |
|
40 | 39 | } |
41 | 40 | function addMarker() { |
42 | 41 | if (!featureGroup.hasLayer(marker)) { |
| 42 | + var xmax = 120, xmin = 100, ymax = 50, ymin = 20; |
| 43 | + marker = L.circleMarker([ |
| 44 | + Math.floor(Math.random() * (ymax - ymin + 1) + ymin), |
| 45 | + Math.floor(Math.random() * (xmax - xmin + 1) + xmin) |
| 46 | + ], {color: "red"}); |
43 | 47 | featureGroup.addLayer(marker); |
| 48 | + map.setView(marker.getLatLng()); |
44 | 49 | } else { |
45 | 50 | alert("请先清除结果"); |
46 | 51 | } |
|
69 | 74 | if (!featureGroup.hasLayer(marker)) { |
70 | 75 | return; |
71 | 76 | } |
72 | | - L.supermap.editFeaturesService(urlCapital).editFeatures({ |
73 | | - IDs: [id], |
74 | | - editType: "delete" |
75 | | - }).on("complete", function (serviceResult) { |
76 | | - if (serviceResult.result.succeed) { |
77 | | - resultLayer.removeFrom(map); |
78 | | - me.initFeature(); |
79 | | - } else { |
80 | | - alert("删除失败") |
81 | | - } |
82 | | - }); |
| 77 | + if (id) { |
| 78 | + L.supermap.editFeaturesService(urlCapital).editFeatures({ |
| 79 | + IDs: [id], |
| 80 | + editType: "delete" |
| 81 | + }).on("complete", function (serviceResult) { |
| 82 | + if (serviceResult.result.succeed) { |
| 83 | + resultLayer.removeFrom(map); |
| 84 | + me.initFeature(); |
| 85 | + } else { |
| 86 | + alert("删除失败") |
| 87 | + } |
| 88 | + }); |
| 89 | + } |
83 | 90 | if (featureGroup && featureGroup.hasLayer(marker)) { |
84 | 91 | featureGroup.removeLayer(marker); |
| 92 | + marker=null; |
85 | 93 | } |
86 | 94 | } |
87 | 95 | </script> |
|
0 commit comments