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%}
#info{position:fixed;background-color:rgba(13, 13, 13, 0.5);padding:10px 10px 10px 10px;font:13px bold sans-serif;color:#fff;left:0px;top:0px;width:100%;height:100px;overflow:hidden;z-index:1000}
</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 id="info"></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);
addOverlay()
}
function addOverlay() {
this.vectorLayer = new GL.VectorLayer('vectorLayer');
this.map.addLayer(this.vectorLayer);
this.text = new GL.Text('120.74434,31.2691366', "I'm a Text");
this.vectorLayer.addOverlay(this.text);
this.text.on('click', onClick);
this.point = new GL.Point(this.map.getCenter(), new GL.Icon.Smart('/examples/static/icons/0003.png', [36, 36]));
this.point.bindLabel("I'm a Point");
this.vectorLayer.addOverlay(this.point);
this.point.on('click', onClick);
this.polyline = new GL.Polyline('120.4240266,31.2978477;120.5144571,31.2960899');
this.polyline.bindLabel("I'm a polyline");
this.vectorLayer.addOverlay(this.polyline);
this.polyline.on('click', onClick);
this.polygon = new GL.Polygon('120.5240266,31.2978477;120.7144571,31.2860899;120.6541053,31.246285');
this.polygon.bindLabel("I'm a polygon");
this.vectorLayer.addOverlay(this.polygon);
this.polygon.on('click', onClick);
}
function onClick(e) {
var infoDom = document.getElementById('info');
infoDom.innerHTML = '<div>' + new Date().toLocaleString() +
' -> 点击 ' + e.target.type + ',坐标为: ' + e.lnglat.toString() + '</div>' +
infoDom.innerHTML;
}
GL.init(initMap, '/examples/static/conf.json');
</script>
</body>
</html>