1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- <!--********************************************************************
- * Copyright© 2000 - 2021 SuperMap Software Co.Ltd. All rights reserved.
- *********************************************************************-->
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <title data-i18n="resources.title_GeoJSON"></title>
- </head>
- <body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%;position: absolute;top: 0;">
- <div id="map" style="margin:0 auto;width: 100%;height: 100%"></div>
- <script type="text/javascript" include="bootstrap" src="../js/include-web.js"></script>
- <script type="text/javascript" exclude="iclient-classic" include="OSMBuildings-SuperMap"
- src="../../dist/classic/include-classic.js"></script>
- <script type="text/javascript">
- var map, layer,vLayer,
- host = window.isLocal ? window.server : "https://iserver.supermap.io";
- url = host + "/iserver/services/map-world/rest/maps/World";
- //初始化地图
- map = new SuperMap.Map("map", {
- controls: [
- new SuperMap.Control.Navigation(),
- new SuperMap.Control.MousePosition(),
- new SuperMap.Control.LayerSwitcher(),
- new SuperMap.Control.Zoom()
- ]
- });
- //初始化图层
- layer = new SuperMap.Layer.TiledDynamicRESTLayer("World", url, null, {maxResolution: "auto"});
- vLayer = new SuperMap.Layer.Vector("vector");
- //监听图层信息加载完成事件
- layer.events.on({"layerInitialized": addLayer});
- //异步加载图层
- function addLayer() {
- map.addLayers([layer, vLayer]);
- map.setCenter(new SuperMap.LonLat(102.0, 0.5), 4);
- //GeoJSON对象,也可以是一个字符串
- var geojson = {
- "type": "FeatureCollection",
- "features": [
- {
- "type": "Feature",
- "geometry": {"type": "Point", "coordinates": [102.0, 0.5]},
- "properties": {"prop0": "value0"}
- },
- {
- "type": "Feature",
- "geometry": {
- "type": "LineString",
- "coordinates": [
- [102.0, 0.0], [103.0, 1.0], [104.0, 0.0], [105.0, 1.0]
- ]
- },
- "properties": {
- "prop0": "value0",
- "prop1": 0.0
- }
- },
- {
- "type": "Feature",
- "geometry": {
- "type": "Polygon",
- "coordinates": [
- [[100.0, 0.0], [101.0, 0.0], [101.0, 1.0],
- [100.0, 1.0], [100.0, 0.0]]
- ]
- },
- "properties": {
- "prop0": "value0",
- "prop1": {"this": "that"}
- }
- }
- ]
- };
- //创建一个GeoJSON解析器
- var geojsonParse = new SuperMap.Format.GeoJSON();
- //将GeoJSON对象转化成要素数组
- var features = geojsonParse.read(geojson);
- //最后将要素数组加到矢量图层里面进行渲染
- vLayer.addFeatures(features);
- }
- </script>
- </body>
- </html>
|