Day Map combined ArcGIS API for JavaScript implementation point aggregation Clusterlayer__arcgis

Source: Internet
Author: User

Recently made a small website, the base map uses the services of the world map, with some of the GIS features provided by ArcGIS JavaScript. Personally feel that the world map API is simple and easy to use, even my rookie to see a few sample code can quickly make the site containing the map. Just, the current map of heaven and earth, Basically only data, there is no GIS related to ESRI's stuff.

Look at ESRI's Clusterlayer sample code on the Internet, the URL is as follows: Https://developers.arcgis.com/javascript/jssamples/layers_point_ Clustering.html and according to some of the domestic technical cow wrote articles, to modify. Because it is quite a dish of rookie, there may be a lot of problems, rather tangled a little bit of investigation.

Question 1: World map does not show

Day map of the class library before the normal test, in the Clusterlayer is not shown. After the line by row debugging, found that the class library of the world map and the class library in Clusterlayer together require, there are strange points of view. During debugging, The class library of the day map does not correctly point to the code it writes, but it points to the unknown ESRI code. Later, the map was added to a separate require block, which showed normal maps.

Problem 2:clusterlayer not displayed

The problem is quite an egg. After basically looking at ESRI's clusterlayer code, we found

Question 2.1 In the World map page, no matter how the scale, the number of clusters in the Clusterlayer is consistent with the number of the original data, does not appear with the scaling and aggregation effect (the effect is the data level, the number of aggregates is not the display level, because the data do not show ....) ), after careful debugging, found that the _clusterresolution value and Ersi provided by the sample code of the value of a lot of difference between the number of levels. Further tracking, found that the value of map.extent.getWidth () is quite small, only single-digit digits. Further verification of the findings, The bottom-chart data in ESRI's sample code is a arcgisonline graph with a space reference of webmercator,wkid:102100. The space reference for the encapsulated ArcGIS JavaScript version of the world map is wgs84,wkid:4326. , in the Clusterlayer, the Map.extent.getWdith () has a small problem, which leads to the subsequent clustering anomaly.

Workaround: In Clusterlayer, change the _clusterresolution to read as follows:

if (Map.spatialReference.isWebMercator ()) {
                this._clusterresolution = Map.extent.getWidth ()/map.width;// Probably a bad default ...
            }
            else {
                //wgs 84 coordinates, converted to web Mercator
                var latlng1 = new Point (Map.extent.xmax, Map.extent.ymax, Map.spatialreference); upper right corner
                var latlng2 = new Point (Map.extent.xmin, Map.extent.ymin, map.spatialreference);//lower left corner
                var webMercator1 = Webmercatorutils.geographictowebmercator (latlng1);
                var WebMercator2 = Webmercatorutils.geographictowebmercator (latlng2);
                This._clusterresolution = (webmercator1.x-webmercator2.x)/map.width;
            }

After the modification is complete, the source data level, you can see the number of clusters with the zoom and change in the dynamic.

Problem 2.2 Clusterlayer not displayed. After the problem is resolved, there is still no aggregation point in the map. In the code in a variety of debugging, all kinds of speculation, a variety of thinking, and in the interface of the output of the core of the Clusterlayer parameters, such as graphics.length, found that the results are normal, That is, there is no aggregation point displayed. Think that there is some kind of conflict between the display mechanism and graphics of heaven and earth diagram, add some graphics to oneself, the layer also shows normal. Tangled up nearly a day, evening suddenly want to understand, or coordinate system problem! The official Clusterlayer is based on the webmercator projection, so the coordinates of the dot cluster after the aggregation are still webmercator, because the Arcgisonline diagram given in the example code is also based on Webmercator, so The point can be displayed normally. and the online Map package library is based on the WGS84 latitude and longitude coordinates. Therefore, after the aggregation of the point cluster coordinates, can not be shown, because far beyond the latitude and longitude of the coordinate range.

Workaround: After the aggregation of the dot cluster coordinates, and then converted to WGS84 coordinates, you can. Modify the following function in Clusterlayer:

_showallclusters:function () {var tp;
            if (Map.spatialReference.isWebMercator ()) {//map is the Webmercator coordinate system tp= "WEBM";
            else {//map is a webmercator coordinate system tp= "NOWEBM";
                for (var i = 0, il = this._clusters.length i < il; i++) {var c = this._clusters[i];
            This._showcluster (C,TP);
                }, _showcluster:function (c, TP) {var point if (tp = "WEBM") {
            Point = new Point (c.x, C.y, THIS._SR);
                else {var latlng = new Point (parsefloat (c.x), parsefloat (C.Y), THIS._SR);
            Point = Webmercatorutils.webmercatortogeographic (LATLNG);
                This.add New Graphic (point, NULL, C.attributes));

Tangled up the problem of N long, finally resolved!


Turn from: http://www.mamicode.com/info-detail-613651.html


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.