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 +); diff --git a/MapTour/src/app/storymaps/maptour/core/MainView.js b/MapTour/src/app/storymaps/maptour/core/MainView.js index 488d66e..81484d7 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, @@ -280,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 @@ -302,9 +306,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 +419,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 +1508,4 @@ define(["storymaps/maptour/core/WebApplicationData", }; }; } -); \ No newline at end of file +); 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 +);