123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- <!--********************************************************************
- * Copyright© 2000 - 2021 SuperMap Software Co.Ltd. All rights reserved.
- *********************************************************************-->
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="UTF-8">
- <title data-i18n="resources.title_snapDrawFeatures"></title>
- <script type="text/javascript" src="../../dist/ol/include-ol.js"></script>
- <style>
- .ol-popup {
- position: absolute;
- top: 50px;
- right: 20px;
- }
- </style>
- </head>
- <body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%;position: absolute;top: 0;">
- <div id="map" style="width: 100%;height:100%"></div>
- <div id="popup" class="ol-popup">
- <div class="btn-group" role="group" aria-label="...">
- <button id="drawPoint" value='Point' type="button" class="btn btn-default"
- data-i18n="resources.text_input_value_drawPoint">
- </button>
- <button id="drawLine" value='LineString' type="button" class="btn btn-default"
- data-i18n="resources.text_input_value_drawLine">
- </button>
- <button id="drawPolygon" value='Polygon' type="button" class="btn btn-default"
- data-i18n="resources.text_input_value_drawPolygon">
- </button>
- <button id="drawCircle" value='Circle' type="button" class="btn btn-default"
- data-i18n="resources.btn_drawCircle">
- </button>
- <button id="none" value='None' type="button" class="btn btn-default" data-i18n="resources.btn_notDraw">
- </button>
- <button id="clear" value='Clear' type="button" class="btn btn-default"
- data-i18n="resources.text_input_value_clear">
- </button>
- </div>
- </div>
- <script type="text/javascript" include="bootstrap,jquery" src="../js/include-web.js"></script>
- <script type="text/javascript">
- var map, draw, snap,
- url = (window.isLocal ? window.server : "https://iserver.supermap.io") + "/iserver/services/map-china400/rest/maps/China";
- map = new ol.Map({
- target: 'map',
- controls: ol.control.defaults({attributionOptions: {collapsed: false}})
- .extend([new ol.supermap.control.Logo()]),
- view: new ol.View({
- center: [12957388, 4853991],
- zoom: 4,
- projection: 'EPSG:3857',
- multiWorld: true
- })
- });
- var layer = new ol.layer.Tile({
- source: new ol.source.TileSuperMapRest({
- url: url,
- wrapX: true
- }),
- projection: 'EPSG:3857'
- });
- var source = new ol.source.Vector({wrapX: false});
- var vector = new ol.layer.Vector({
- source: source
- });
- map.addLayer(layer);
- map.addLayer(vector);
- var info = new ol.control.Control({element: document.getElementById('popup')});
- info.setMap(map);
- map.addControl(info);
- var buttons = $('.btn-group').children();
- buttons.map(function (key) {
- var value = buttons[key].value;
- if (value === 'None') {
- $(buttons[key]).on('click', function () {
- clearInteraction();
- });
- return;
- }
- if (value === 'Clear') {
- $(buttons[key]).on('click', function () {
- clearInteraction();
- source.clear();
- });
- return;
- }
- $(buttons[key]).on('click', function () {
- clearInteraction();
- draw = new ol.interaction.Draw({
- source: source,
- type: buttons[key].value,
- snapTolerance: 20
- });
- map.addInteraction(draw);
- snap = new ol.interaction.Snap({
- source: source
- });
- map.addInteraction(snap);
- });
- });
- function clearInteraction() {
- if (draw) {
- map.removeInteraction(draw);
- }
- if (snap) {
- map.removeInteraction(snap);
- }
- }
- </script>
- </body>
- </html>
|