From 05cd931f0ef7a637409f9fc8f2bf01222a503bc8 Mon Sep 17 00:00:00 2001 From: sharif26 Date: Fri, 2 Sep 2016 09:40:45 -0500 Subject: [PATCH 1/4] Update FeatureServiceManager.js coded added to handle feature layer with polygon, getCentroid() function is used in case of polygon type. --- .../maptour/core/FeatureServiceManager.js | 82 +++++++++++++------ 1 file changed, 57 insertions(+), 25 deletions(-) diff --git a/MapTour/src/app/storymaps/maptour/core/FeatureServiceManager.js b/MapTour/src/app/storymaps/maptour/core/FeatureServiceManager.js index ba2463e..af925db 100644 --- a/MapTour/src/app/storymaps/maptour/core/FeatureServiceManager.js +++ b/MapTour/src/app/storymaps/maptour/core/FeatureServiceManager.js @@ -2,12 +2,14 @@ define(["storymaps/maptour/core/TourPointAttributes", "storymaps/maptour/core/MapTourHelper", "esri/graphic", "esri/geometry/Point", + "esri/geometry/Polygon", "dojo/topic"], function ( TourPointAttributes, MapTourHelper, Graphic, Point, + Polygon, topic ) { return function FeatureServiceManager() @@ -31,16 +33,29 @@ define(["storymaps/maptour/core/TourPointAttributes", if( isFSWithURLFields || ! featureLayer.hasAttachments ) { for (i = 0; i < featureLayer.graphics.length; i++) { var feature = featureLayer.graphics[i]; - var graphic = new Graphic( - new Point( - feature.geometry.x, - feature.geometry.y, - feature.geometry.spatialReference - ), - null, - new TourPointAttributes(feature) - ); - graphics.push(graphic); + //added code here to support point & polygon + if(feature.geometry.type == "point") { + var graphic = new Graphic( + new Point( + feature.geometry.x, + feature.geometry.y, + feature.geometry.spatialReference + ), + null, + new TourPointAttributes(feature) + ); + graphics.push(graphic); + } + else if(feature.geometry.type == "polygon") { + //get the centroid when the feature is polygon + var graphic = new Graphic( + new Point( feature.geometry.getCentroid() ), + null, + new TourPointAttributes(feature) + ); + graphics.push(graphic); + } +// graphics.push(graphic); } publishCompleteEvent(); } @@ -80,21 +95,38 @@ define(["storymaps/maptour/core/TourPointAttributes", // Check the type of attachment if( MapTourHelper.isSupportedImgExt(pict.name) && MapTourHelper.isSupportedImgExt(thumb.name) ) { - var graphic = new Graphic( - new Point( - feature.geometry.x, - feature.geometry.y, - feature.geometry.spatialReference - ), - null, - new TourPointAttributes( - feature, - pict.url, - thumb.url - ) - ); + //added code here to support point & polygon + if(feature.geometry.type == "point") { + var graphic = new Graphic( + new Point( + feature.geometry.x, + feature.geometry.y, + feature.geometry.spatialReference + ), + null, + new TourPointAttributes( + feature, + pict.url, + thumb.url + ) + ); + graphics.push(graphic); + } + else if(feature.geometry.type == "polygon") { + //get the centroid when the feature is polygon + var graphic = new Graphic( + new Point( feature.geometry.getCentroid() ), + null, + new TourPointAttributes( + feature, + pict.url, + thumb.url + ) + ); + graphics.push(graphic); + } - graphics.push(graphic); +// graphics.push(graphic); } } @@ -119,4 +151,4 @@ define(["storymaps/maptour/core/TourPointAttributes", } }; } -); \ No newline at end of file +); From 7fe4e7bad4263315558a6259d0c5bf2357a1c4cd Mon Sep 17 00:00:00 2001 From: sharif26 Date: Fri, 2 Sep 2016 09:59:52 -0500 Subject: [PATCH 2/4] Update MainView.js code changed to support polygon shape. --- .../app/storymaps/maptour/core/MainView.js | 28 ++++++++++++++----- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/MapTour/src/app/storymaps/maptour/core/MainView.js b/MapTour/src/app/storymaps/maptour/core/MainView.js index 488d66e..96420f8 100644 --- a/MapTour/src/app/storymaps/maptour/core/MainView.js +++ b/MapTour/src/app/storymaps/maptour/core/MainView.js @@ -19,6 +19,7 @@ define(["storymaps/maptour/core/WebApplicationData", "esri/renderers/UniqueValueRenderer", "esri/graphic", "esri/geometry/Point", + "esri/geometry/Polygon", "esri/geometry/Extent", "esri/config", "esri/geometry/webMercatorUtils", @@ -49,6 +50,7 @@ define(["storymaps/maptour/core/WebApplicationData", UniqueValueRenderer, Graphic, Point, + Polygon, Extent, esriConfig, webMercatorUtils, @@ -302,9 +304,11 @@ define(["storymaps/maptour/core/WebApplicationData", layer = app.map._layers[layerName]; // Catch visible FS and webmap embedded point layers + // added code to support Polygon if( (layer.visible || layer.visible === undefined) && (layer.type == "Feature Layer" || layer._collection) - && layer.geometryType == "esriGeometryPoint" + && (layer.geometryType == "esriGeometryPoint" || layer.geometryType == "esriGeometryPolygon") +// && layer.geometryType == "esriGeometryPoint" && ! layerName.match(/^mapNotes_/) ) { // If it's a webmap layer check that all mandatory fields are present to allow additional decoration layer @@ -413,11 +417,21 @@ define(["storymaps/maptour/core/WebApplicationData", var graphics = []; $(app.data.getSourceLayer().graphics).each(function(i, graphic) { - graphics.push(new Graphic( - new Point(graphic.geometry.x, graphic.geometry.y, graphic.geometry.spatialReference), - null, - new TourPointAttributes(graphic, null, null, true) - )); + //added code here to support point & polygon (in case csv may contain polygon info) + if(graphic.geometry.type == "point") { + graphics.push(new Graphic( + new Point(graphic.geometry.x, graphic.geometry.y, graphic.geometry.spatialReference), + null, + new TourPointAttributes(graphic, null, null, true) + )); + } + else if(graphic.geometry.type == "polygon") { + graphics.push(new Graphic( + new Point(graphic.geometry.getCentroid()), + null, + new TourPointAttributes(graphic, null, null, true) + )); + } }); tourPointLayerLoaded({ graphics: graphics }); @@ -1492,4 +1506,4 @@ define(["storymaps/maptour/core/WebApplicationData", }; }; } -); \ No newline at end of file +); From ec004085d232ec8490d635efc2b8a4a410a4d59c Mon Sep 17 00:00:00 2001 From: sharif26 Date: Fri, 2 Sep 2016 10:02:44 -0500 Subject: [PATCH 3/4] Update TourData.js added code to support polygon shape --- MapTour/src/app/storymaps/maptour/core/TourData.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/MapTour/src/app/storymaps/maptour/core/TourData.js b/MapTour/src/app/storymaps/maptour/core/TourData.js index 7f979cd..77e17d0 100644 --- a/MapTour/src/app/storymaps/maptour/core/TourData.js +++ b/MapTour/src/app/storymaps/maptour/core/TourData.js @@ -8,6 +8,7 @@ define(["storymaps/maptour/core/WebApplicationData", "esri/layers/FeatureLayer", "esri/graphic", "esri/geometry/Point", + "esri/geometry/Polygon", "dojo/topic"], function( WebApplicationData, @@ -20,6 +21,7 @@ define(["storymaps/maptour/core/WebApplicationData", FeatureLayer, Graphic, Point, + Polygon, topic ){ /** @@ -532,7 +534,14 @@ define(["storymaps/maptour/core/WebApplicationData", var nbPointsBeforeImport = this.getTourPoints(false).length; $.each(featureCollection.featureSet.features, function(i, feature){ - addTourPointUsingAttributes(new Point(feature.geometry), feature.attributes); + //added code here to support point & polygon + if(feature.geometry.type == "point") { + addTourPointUsingAttributes(new Point(feature.geometry), feature.attributes); + } + else if(feature.geometry.type == "polygon") { + addTourPointUsingAttributes(new Point(feature.geometry.getCentroid()), feature.attributes); + } +// addTourPointUsingAttributes(new Point(feature.geometry), feature.attributes); }); processPointsOrder( computeTourPointOrderFromConfig() ); @@ -1208,4 +1217,4 @@ define(["storymaps/maptour/core/WebApplicationData", }; }; } -); \ No newline at end of file +); From 55a6e5e8550def7c2c1daf76b727f028cc6bfcd8 Mon Sep 17 00:00:00 2001 From: sharif26 Date: Fri, 2 Sep 2016 10:06:32 -0500 Subject: [PATCH 4/4] Update MainView.js --- MapTour/src/app/storymaps/maptour/core/MainView.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/MapTour/src/app/storymaps/maptour/core/MainView.js b/MapTour/src/app/storymaps/maptour/core/MainView.js index 96420f8..81484d7 100644 --- a/MapTour/src/app/storymaps/maptour/core/MainView.js +++ b/MapTour/src/app/storymaps/maptour/core/MainView.js @@ -282,7 +282,9 @@ define(["storymaps/maptour/core/WebApplicationData", layerId = layerId.split('_').slice(0,1).join('_'); // Exclude map notes and not point layers - if( layerId.match(/^mapNotes_/) || layer.geometryType != "esriGeometryPoint" ) + // changed code to support Polygon +// if( layerId.match(/^mapNotes_/) || layer.geometryType != "esriGeometryPoint" ) + if( layerId.match(/^mapNotes_/) || (layer.geometryType != "esriGeometryPoint" && layer.geometryType != "esriGeometryPolygon") ) continue; // Loop through webmap layers to see if title match