index.html
<!DOCTYPE html>
<html>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>交互 - 编辑工具</title>
<link rel="icon" href="/examples/static/resource/image/favicon.png" />
<style type="text/css">
html,body{margin:0px;height:100%;width:100%}
.container{width:100%;height:100%}
.pane{line-height:28px;color:#fff;z-index:1000;position:absolute;top:20px;right:20px}
.pane a{display:block;color:#fff;text-align:center;padding:0 10px;min-width:28px;min-height:28px;float:left;background:#34495e}
.pane a:hover{background:#1bbc9b}
.pane a + a{border-left:1px solid #425568}
</style>
<link rel="stylesheet" href="//rd.sz-map.com/libs/gm/gl/gl.min.css">
<script type="text/javascript" src="//rd.sz-map.com/libs/gm/gl/gl.min.js"></script>
<body>
<div id="map" class="container"></div>
<div class="pane">
<a href="javascript:void(0);" onclick="edit('Polyline');">编辑线</a>
<a href="javascript:void(0);" onclick="edit('Polygon');">编辑面</a>
<a href="javascript:void(0);" onclick="edit('Circle');">编辑圆</a>
<a href="javascript:void(0);" onclick="edit('Rectangle');">编辑矩形</a>
<a href="javascript:void(0);" onclick="edit('Point');">编辑点</a>
<a href="javascript:void(0);" onclick="deactivate();">停止编辑</a>
</div>
<script>
function initMap() {
this.map = new GL.Map('map', {
center: '120.650847,31.3092434',
zoomControl: false,
scaleControl: false
});
var crs = {"resolutions":[0.0009765664903423653,0.0004882832451711827,0.00024414162258559134,0.00012207081129279567,0.00006103540564766688,0.000030517702822564394,0.000015258851412551242,0.000007629425705006574,0.000003814712853772333,0.00000190735154359766],"origin":"119.75,32.25"};
var options = {"maxBounds":"119.89,30.75;121.406,32.08","preview":"/examples/static/images/preview.png"};
var baseLayer = GL.LayerLookup.createGaeaTiledLayer(
'http://119.3.130.139/tiles/vector_pc/_alllayers',
Object.assign({}, options, {zIndex: 3}),
crs
);
this.map.addBaseLayer(baseLayer);
drawOverlay();
}
function drawOverlay() {
this.vectorLayer = new GL.VectorLayer();
this.map.addLayer(this.vectorLayer);
this.point = new GL.Point(
[120.58105869, 31.30115627],
new GL.Icon.Smart('/examples/static/icons/0001.png', [32, 32])
);
this.polyline = new GL.Polyline(
'120.62558,31.30043;120.66099,31.30233',
new GL.Style({ color: '#ff0000' }, true)
);
this.polygon = new GL.Polygon(
'120.6114,31.27683;120.6666,31.23761;120.57162,31.21344',
new GL.Style.Fill(
{
fillColor: '#afc333'
},
true
)
);
this.circle = new GL.Circle(
'120.7164177,31.3774596',
5000,
new GL.Style.Fill({ fillColor: '#ff0000' })
);
this.rectangle = new GL.Rectangle(
'120.7044854,31.1987795;120.8133695,31.2604552'
);
this.vectorLayer.addOverlay(this.point);
this.vectorLayer.addOverlay(this.polyline);
this.vectorLayer.addOverlay(this.polygon);
this.vectorLayer.addOverlay(this.circle);
this.vectorLayer.addOverlay(this.rectangle);
}
function edit(type) {
var shape;
switch (type) {
case 'Point':
shape = this.point;
break;
case 'Rectangle':
shape = this.rectangle;
break;
case 'Polyline':
shape = this.polyline;
break;
case 'Polygon':
shape = this.polygon;
break;
case 'Circle':
shape = this.circle;
break;
}
GL.EditTool.activate(shape);
}
function deactivate() {
GL.EditTool.deactivate();
}
GL.init(initMap, '/examples/static/conf.json');
</script>
</body>
</html>