第二篇 arcgis api for js 根据坐标生成点

来源:互联网 发布:mac专柜口红价格 编辑:程序博客网 时间:2024/04/29 19:32

要点

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);                    };

采用第二种方式同样可以生成点。下面采用第三种方式,待续……




0 0
原创粉丝点击