POST
|
Thanks, it's works great, sorry for not replaying before.
... View more
10-27-2015
05:53 PM
|
0
|
1
|
375
|
POST
|
Hello I have a doubt , there is a method as setDefinitionExpression or something for esri.layers.ArcGISDynamicMapServiceLayer
... View more
10-14-2015
03:28 PM
|
0
|
3
|
2501
|
POST
|
Thank you for the advice. in the class map you can find the "layers-add-result" event , that fires after all layer were added so i just change this line map.on("load", initFunctionality); for this one map.on("layers-add-result", initFunctionality); u can see the reference Map (legacy) | API Reference | ArcGIS API for JavaScript .
... View more
09-18-2015
03:25 PM
|
0
|
0
|
619
|
POST
|
I realized that the map.on("load", initFunctionality) does not load the initFunctionality. So what i did was commenting map.on("load", initFunctionality) and header/end of initFunctionality. Like function inittimeSlider() { try{ var opLayer = new esri.layers.ArcGISDynamicMapServiceLayer(document.getElementById('hUrl').value); opLayer.setVisibleLayers([CapaPosicion.FALLAS.value]); opLayer.id = 'timeSlider'; opLayer.opacity = 0.6; var component = dijit.registry.byId("timeSliderDiv"); if (component) { //destroy it dojo.domConstruct.destroy(component); dijit.registry.remove(timeSlider) timeSlider.destroy() } timeSlider = new esri.dijit.TimeSlider({ style: "width: 100%;" }, dojo.dom.byId("timeSliderDiv")); map.setTimeSlider(timeSlider); var timeExtent = new esri.TimeExtent(); timeExtent.startTime = new Date("01/01/2015 UTC"); timeExtent.endTime = new Date("08/31/2015 UTC"); timeSlider.setThumbCount(2); timeSlider.createTimeStopsByTimeInterval(timeExtent, 1, "esriTimeUnitsMonths"); timeSlider.setThumbIndexes([0, 1]); timeSlider.setThumbMovingRate(2000); timeSlider.startup(); //add labels for every other time stop var labels = dojo._base.array.map(timeSlider.timeStops, function (timeStop, i) { //if ( i % 2 === 0 ) { return timeStop.getUTCFullYear(); //} else { return ""; //} }); timeSlider.setLabels(labels); timeSlider.on("time-extent-change", function (evt) { var startValString = Meses(evt.startTime.getUTCMonth()); var endValString = Meses(evt.endTime.getUTCMonth()); dojo.dom.byId("daterange").innerHTML = "<i>" + startValString + " a " + endValString + " " + "<\/i>"; }); map.addLayers([opLayer]); map.on("load", initFunctionality); function initFunctionality() { map.on("click", doIdentify); var identifyTask = new esri.tasks.IdentifyTask(document.getElementById('hUrl').value); var identifyParams = new esri.tasks.IdentifyParameters(); identifyParams.tolerance = 3; identifyParams.returnGeometry = true; identifyParams.layerIds = [CapaPosicion.FALLAS.value]; identifyParams.layerOption = esri.tasks.IdentifyParameters.LAYER_OPTION_ALL; dojo.on(identifyTask, "complete", function (event) { array.forEach(event.results, function (feature) { if (feature.layerName == "timeSlider") { alert('123456789'); } }); }); } function doIdentify(event) { map.graphics.clear(); identifyParams.geometry = event.mapPoint; identifyParams.mapExtent = map.extent; identifyTask.execute(identifyParams) } } catch (e) { console.log("Error : " + e); HideProgress(); } } i do not know why the map.on("load", initFunctionality); it does not work but the map.on("click", doIdentify); works well . Maybe i not using the proper method or something else. by the way, following the advice to add console.info('Identify Reults:', event.results); in the original code did not work, only if i remove the lines that i said before.
... View more
09-18-2015
12:26 PM
|
0
|
2
|
619
|
POST
|
Hi, I'm trying to replicate this Onclick event for a sublayer in a ArcGISDynamicMapServiceLayer sample but i hadn't success. Mine scenario are: I've a menu each action can show a different view of data (layers) one of those are a time TimeSlider, the time slider works fine but a need to add a function for display some data after doing a click on certain point on the map. function inittimeSlider() { try{ var opLayer = new esri.layers.ArcGISDynamicMapServiceLayer(document.getElementById('hUrl').value); opLayer.setVisibleLayers([CapaPosicion.FALLAS.value]); opLayer.id = 'timeSlider'; opLayer.opacity = 0.6; var component = dijit.registry.byId("timeSliderDiv"); if (component) { //destroy it dojo.domConstruct.destroy(component); dijit.registry.remove(timeSlider) timeSlider.destroy() } timeSlider = new esri.dijit.TimeSlider({ style: "width: 100%;" }, dojo.dom.byId("timeSliderDiv")); map.setTimeSlider(timeSlider); var timeExtent = new esri.TimeExtent(); timeExtent.startTime = new Date("01/01/2015 UTC"); timeExtent.endTime = new Date("08/31/2015 UTC"); timeSlider.setThumbCount(2); timeSlider.createTimeStopsByTimeInterval(timeExtent, 1, "esriTimeUnitsMonths"); timeSlider.setThumbIndexes([0, 1]); timeSlider.setThumbMovingRate(2000); timeSlider.startup(); //add labels for every other time stop var labels = dojo._base.array.map(timeSlider.timeStops, function (timeStop, i) { //if ( i % 2 === 0 ) { return timeStop.getUTCFullYear(); //} else { return ""; //} }); timeSlider.setLabels(labels); timeSlider.on("time-extent-change", function (evt) { var startValString = Meses(evt.startTime.getUTCMonth()); var endValString = Meses(evt.endTime.getUTCMonth()); dojo.dom.byId("daterange").innerHTML = "<i>" + startValString + " a " + endValString + " " + "<\/i>"; }); map.addLayers([opLayer]); map.on("load", initFunctionality); function initFunctionality() { map.on("click", doIdentify); var identifyTask = new esri.tasks.IdentifyTask(document.getElementById('hUrl').value); var identifyParams = new esri.tasks.IdentifyParameters(); identifyParams.tolerance = 3; identifyParams.returnGeometry = true; identifyParams.layerIds = [CapaPosicion.FALLAS.value]; identifyParams.layerOption = esri.tasks.IdentifyParameters.LAYER_OPTION_ALL; dojo.on(identifyTask, "complete", function (event) { array.forEach(event.results, function (feature) { if (feature.layerName == "timeSlider") { alert('123456789'); } }); }); } function doIdentify(event) { map.graphics.clear(); identifyParams.geometry = event.mapPoint; identifyParams.mapExtent = map.extent; identifyTask.execute(identifyParams) } } catch (e) { console.log("Error : " + e); HideProgress(); } } at first I thought it was the same way to what is done in the onclick of esri.layers.FeatureLayer, exist another way ? or I have something wrong that can not see ?
... View more
09-17-2015
02:25 PM
|
0
|
6
|
3396
|
POST
|
It's a flie that contains ClusterLayer.js the code is:>> dojo.provide("extras.ClusterLayer"); dojo.require("esri.layers.graphics"); dojo.require("dojo._base.declare"); dojo.require("dojo._base.array"); dojo.require("esri.Color"); dojo.require("dojo._base.connect"); dojo.require("esri.SpatialReference"); dojo.require("esri.geometry.Point"); dojo.require("esri.graphic"); dojo.require("esri.symbols.SimpleMarkerSymbol"); dojo.require("esri.symbols.PictureMarkerSymbol"); dojo.require("esri.renderers.ClassBreaksRenderer"); dojo.require("esri.symbols.TextSymbol"); dojo.require("esri.dijit.PopupTemplate"); dojo.require("esri.layers.GraphicsLayer"); dojo.declare("extras.ClusterLayer", esri.layers.GraphicsLayer, { constructor: function (options) { // options: // data: Object[] // Array of objects. Required. Object are required to have properties named x, y and attributes. The x and y coordinates have to be numbers that represent a points coordinates. // distance: Number? // Optional. The max number of pixels between points to group points in the same cluster. Default value is 50. // labelColor: String? // Optional. Hex string or array of rgba values used as the color for cluster labels. Default value is #fff (white). // labelOffset: String? // Optional. Number of pixels to shift a cluster label vertically. Defaults to -5 to align labels with circle symbols. Does not work in IE. // resolution: Number // Required. Width of a pixel in map coordinates. Example of how to calculate: // map.extent.getWidth() / map.width // showSingles: Boolean? // Optional. Whether or graphics should be displayed when a cluster graphic is clicked. Default is true. // singleSymbol: MarkerSymbol? // Marker Symbol (picture or simple). Optional. Symbol to use for graphics that represent single points. Default is a small gray SimpleMarkerSymbol. // singleTemplate: PopupTemplate? // PopupTemplate</a>. Optional. Popup template used to format attributes for graphics that represent single points. Default shows all attributes as "attribute = value" (not recommended). // maxSingles: Number? // Optional. Threshold for whether or not to show graphics for points in a cluster. Default is 1000. // webmap: Boolean? // Optional. Whether or not the map is from an ArcGIS.com webmap. Default is false. // spatialReference: SpatialReference? // Optional. Spatial reference for all graphics in the layer. This has to match the spatial reference of the map. Default is 102100. Omit this if the map uses basemaps in web mercator. this._onClickEvento = options.onClickEvent; this._clusterTolerance = options.distance || 100; this._clusterData = options.data || []; this._clusters = []; this._clusterLabelColor = options.labelColor || "#000"; // labelOffset can be zero so handle it differently this._clusterLabelOffset = (options.hasOwnProperty("labelOffset")) ? options.labelOffset : -5; // graphics that represent a single point this._singles = []; // populated when a graphic is clicked this._showSingles = options.hasOwnProperty("showSingles") ? options.showSingles : true; // symbol for single graphics var SMS = esri.symbol.SimpleMarkerSymbol; this._singleSym = options.singleSymbol || new SMS("circle", 6, null, new esri.Color("#000000")); //this._singleTemplate = options.singleTemplate || new esri.dijit.PopupTemplate({ "title": "", "description": "{*}" }); this._maxSingles = 3000; this._webmap = options.hasOwnProperty("webmap") ? options.webmap : false; this._sr = options.spatialReference || new esri.SpatialReference({ "wkid": 102100 }); this._zoomEnd = null; }, // override esri/layers/GraphicsLayer methods _setMap: function (map, surface) { // calculate and set the initial resolution this._clusterResolution = map.extent.getWidth() / map.width; // probably a bad default... this._clusterGraphics(); // connect to onZoomEnd so data is re-clustered when zoom level changes this._zoomEnd = dojo.connect(map, "onZoomEnd", this, function () { // update resolution this._clusterResolution = this._map.extent.getWidth() / this._map.width; this.clear(); this._clusterGraphics(); }); // GraphicsLayer will add its own listener here var div = this.inherited(arguments); return div; }, _unsetMap: function () { this.inherited(arguments); dojo.disconnect(this._zoomEnd); }, // public ClusterLayer methods add: function (p) { // Summary: The argument is a data point to be added to an existing cluster. If the data point falls within an existing cluster, it is added to that cluster and the cluster's label is updated. If the new point does not fall within an existing cluster, a new cluster is created. // // if passed a graphic, use the GraphicsLayer's add method if (p.declaredClass) { this.inherited(arguments); return; } // add the new data to _clusterData so that it's included in clusters // when the map level changes this._clusterData.push(p); var clustered = false; // look for an existing cluster for the new point for (var i = 0; i < this._clusters.length; i++) { var c = this._clusters; if (this._clusterTest(p, c)) { // add the point to an existing cluster this._clusterAddPoint(p, c); // update the cluster's geometry this._updateClusterGeometry(c); // update the label this._updateLabel(c); clustered = true; break; } } if (!clustered) { this._clusterCreate(p); p.attributes.clusterCount = 1; this._showCluster(p); } }, clear: function () { // Summary: Remove all clusters and data points. this.inherited(arguments); this._clusters.length = 0; }, clearSingles: function (singles) { // Summary: Remove graphics that represent individual data points. var s = singles || this._singles; dojo.forEach(s, function (g) { this.remove(g); }, this); this._singles.length = 0; }, onClick: function (e) { ShowProgress(); // remove any previously showing single features this.clearSingles(this._singles); // find single graphics that make up the cluster that was clicked // would be nice to use filter but performance tanks with large arrays in IE var singles = []; for (var i = 0, il = this._clusterData.length; i < il; i++) { if (e.graphic.attributes.clusterId == this._clusterData.attributes.clusterId) { singles.push(this._clusterData); } } // if (singles.length > this._maxSingles) { // alert("Cluster con m" + '\u00e1' + "s de " + this._maxSingles + " puntos. Aplicar zoom para mostrar detalle."); // return; // } else { // // stop the click from bubbling to the map // e.stopPropagation(); // this._map.infoWindow.show(e.graphic.geometry); // //this._addSingles(singles); // } this._onClickEvento(singles); }, // internal methods _clusterGraphics: function () { // first time through, loop through the points for (var j = 0, jl = this._clusterData.length; j < jl; j++) { // see if the current feature should be added to a cluster var point = this._clusterData ; var clustered = false; var numClusters = this._clusters.length; for (var i = 0; i < this._clusters.length; i++) { var c = this._clusters; if (this._clusterTest(point, c)) { this._clusterAddPoint(point, c); clustered = true; break; } } if (!clustered) { this._clusterCreate(point); } } this._showAllClusters(); }, _clusterTest: function (p, cluster) { var distance = ( Math.sqrt( Math.pow((cluster.x - p.x), 2) + Math.pow((cluster.y - p.y), 2) ) / this._clusterResolution ); return (distance <= this._clusterTolerance); }, // points passed to clusterAddPoint should be included // in an existing cluster // also give the point an attribute called clusterId // that corresponds to its cluster _clusterAddPoint: function (p, cluster) { // average in the new point to the cluster geometry var count, x, y; count = cluster.attributes.clusterCount; x = (p.x + (cluster.x * count)) / (count + 1); y = (p.y + (cluster.y * count)) / (count + 1); cluster.x = x; cluster.y = y; // build an extent that includes all points in a cluster // extents are for debug/testing only...not used by the layer if (p.x < cluster.attributes.extent[0]) { cluster.attributes.extent[0] = p.x; } else if (p.x > cluster.attributes.extent[2]) { cluster.attributes.extent[2] = p.x; } if (p.y < cluster.attributes.extent[1]) { cluster.attributes.extent[1] = p.y; } else if (p.y > cluster.attributes.extent[3]) { cluster.attributes.extent[3] = p.y; } // increment the count cluster.attributes.clusterCount++; // attributes might not exist if (!p.hasOwnProperty("attributes")) { p.attributes = {}; } // give the graphic a cluster id p.attributes.clusterId = cluster.attributes.clusterId; //p.attributes.clusterPoint = (cluster.attributes.clusterCount === 0 ? 0 : cluster.attributes.clusterCount); //debugger; }, // point passed to clusterCreate isn't within the // clustering distance specified for the layer so // create a new cluster for it _clusterCreate: function (p) { var clusterId = this._clusters.length + 1; //var clusterPoint = (this._clusters.length === 0 || this._clusters.length === undefined) ? 0 : this._clusters.length; // console.log("cluster create, id is: ", clusterId); // p.attributes might be undefined if (!p.attributes) { p.attributes = {}; } p.attributes.clusterId = clusterId; // create the cluster var cluster = { "x": p.x, "y": p.y, "attributes": { "clusterCount": 1, //"clusterPoint": 1, "clusterId": clusterId, "extent": [p.x, p.y, p.x, p.y] } }; this._clusters.push(cluster); }, _showAllClusters: function () { for (var i = 0, il = this._clusters.length; i < il; i++) { var c = this._clusters; this._showCluster(c); } }, _showCluster: function (c) { var point = new esri.geometry.Point(c.x, c.y, this._sr); this.add( new esri.Graphic( point, null, c.attributes ) ); // code below is used to not label clusters with a single point if (c.attributes.clusterCount == 1) { return; } // show number of points in the cluster var label = new esri.symbols.TextSymbol(c.attributes.clusterCount) .setColor(new esri.Color(this._clusterLabelColor)) .setOffset(0, this._clusterLabelOffset); this.add( new esri.Graphic( point, label, c.attributes ) ); }, _addSingles: function (singles) { // add single graphics to the map dojo.forEach(singles, function (p) { var g = new esri.Graphic( new esri.geometry.Point(p.x, p.y, this._sr), this._singleSym, p.attributes ,this._singleTemplate ); this._singles.push(g); if (this._showSingles) { this.add(g); } }, this); this._map.infoWindow.setFeatures(this._singles); }, _updateClusterGeometry: function (c) { // find the cluster graphic var cg = dojo.filter(this.graphics, function (g) { return !g.symbol && g.attributes.clusterId == c.attributes.clusterId; //g.attributes.clusterPoint == c.attributes.clusterPoint; }); if (cg.length == 1) { cg[0].geometry.update(c.x, c.y); } else { console.log("didn't find exactly one cluster geometry to update: ", cg); } }, _updateLabel: function (c) { // find the existing label var label = dojo.filter(this.graphics, function (g) { return g.symbol && g.symbol.declaredClass == "esri.symbol.TextSymbol" && g.attributes.clusterId == c.attributes.clusterId; //g.attributes.clusterPoint == c.attributes.clusterPoint; }); if (label.length == 1) { // console.log("update label...found: ", label); this.remove(label[0]); var newLabel = new esri.symbols.TextSymbol(c.attributes.clusterCount) .setColor(new esri.Color(this._clusterLabelColor)) .setOffset(0, this._clusterLabelOffset); this.add( new esri.Graphic( new esri.geometry.Point(c.x, c.y, this._sr), newLabel, c.attributes ) ); // console.log("updated the label"); } else { console.log("didn't find exactly one label: ", label); } }, // debug only...never called by the layer _clusterMeta: function () { // print total number of features console.log("Total: ", this._clusterData.length); // add up counts and print it var count = 0; dojo.forEach(this._clusters, function (c) { count += c.attributes.clusterCount; }); console.log("In clusters: ", count); } }); Is the same code as layers_point_clustering sample Point clustering | ArcGIS API for JavaScript
... View more
09-15-2015
10:18 AM
|
0
|
0
|
360
|
POST
|
Hi, I'm not sure why? but, when i removed this line <script> var timeStamp = Math.round((new Date()).getTime()/1000); var dojoConfig = { parseOnLoad: true, packages: [{ "name": "extras", "location": location.pathname.replace(/\/[^/]+$/, '') + "/extras" }] }; </script> the measurement, started work again. i do not know if this line is complete necessary for the cluster functionality.
... View more
09-15-2015
10:14 AM
|
0
|
0
|
360
|
POST
|
Hi, I recently added a cluster and the following code for getting work with cluster layer. <script> var timeStamp = Math.round((new Date()).getTime()/1000); var dojoConfig = { parseOnLoad: true, packages: [{ "name": "extras", "location": location.pathname.replace(/\/[^/]+$/, '') + "/extras" }] }; </script> but after that I started noticing that the esri.dijit.Measurement stop working (not shows the labels and dropdownlist), when i remove the complete cluster function, the esri.dijit.Measurement work again, with out any problem. So i think that this issue come with firts script. what i doing wrong? i need to have both functions cluster layers and measure tools.
... View more
09-15-2015
08:19 AM
|
0
|
4
|
2914
|
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:24 AM
|