1. 程式人生 > >第二篇 arcgis api for js 根據座標生成點

第二篇 arcgis api for js 根據座標生成點

要點

1、生成點要素

2、地圖載入順序及map.on事件順序;

3、分析兩種不同圖層載入方式對點生成的影響;

可執行程式碼:

</pre><pre>
<%--
  Created by IntelliJ IDEA.
  User: neil
  Date: 2015/8/16
  Time: 18:48
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">
    <title>SimpleMarkerSymbol with SVG Path - Simplified</title>
    <link rel="stylesheet" href="http://js.arcgis.com/3.14/dijit/themes/claro/claro.css">
    <link rel="stylesheet" href="http://js.arcgis.com/3.14/dojox/widget/ColorPicker/ColorPicker.css">
    <link rel="stylesheet" href="http://js.arcgis.com/3.14/esri/css/esri.css">
    <style>
        html, body, #map {
            height: 100%;
            width: 100%;
            margin: 0;
            padding: 0;
        }

    </style>
    <script src="http://js.arcgis.com/3.14/"></script>
    <script>
        var map;

        require([
            "esri/map", "esri/geometry/Point", "esri/SpatialReference",
            "esri/symbols/SimpleMarkerSymbol", "esri/graphic"
        ], function(Map, Point, SpatialReference, SimpleMarkerSymbol, Graphic) {
            map = new Map("map", {
                basemap: "topo",
                center: [113, 37],
                zoom: 13
            });
            map.on("load", function() { ShowLocation(113,37); });

            function ShowLocation(x, y) {
                var point = new Point(x, y, new SpatialReference({wkid:4326}));
                var simpleMarkerSymbol = new SimpleMarkerSymbol();
                var graphic = new Graphic(point, simpleMarkerSymbol);

                map.graphics.add(graphic);
            };
        });
    </script>
</head>
<div id="map"></div>
</body>
</html>

注意,只有當map.on事件緊跟map=new Map(...);之後,才能正常顯示點;

下面換成另一種方式載入瓦片圖層,將上面方法程式碼替換如下:

                function(Map, Tiled,Point, SpatialReference, SimpleMarkerSymbol, Graphic) {
                    map = new Map("map");

                    map.on("load", function() { ShowLocation(113,37); });

                    var tiled = new Tiled("http://server.arcgisonline.com/arcgis/rest/services/World_Topo_Map/MapServer");
                    map.addLayer(tiled);



                    function ShowLocation(x, y) {
                        var point = new Point(x, y, new SpatialReference({wkid:4326}));
                        var simpleMarkerSymbol = new SimpleMarkerSymbol();
                        var graphic = new Graphic(point, simpleMarkerSymbol);

                        map.graphics.add(graphic);
                    };

採用第二種方式同樣可以生成點。下面採用第三種方式,待續……