Giter VIP home page Giter VIP logo

esri / arcgis-js-vscode-snippets Goto Github PK

View Code? Open in Web Editor NEW
25.0 11.0 8.0 2.63 MB

Collection of Visual Studio Code snippets for common code patterns in the ArcGIS Maps SDK for JavaScript.

Home Page: https://marketplace.visualstudio.com/items?itemName=Esri.arcgis-maps-sdk-js-snippets

License: Apache License 2.0

HTML 66.08% CSS 8.86% JavaScript 24.58% TypeScript 0.22% SCSS 0.26%
arcgis-js-api javascript typescript arcgis arcgis-js-sdk esri frontend good-first-issue hacktoberfest hacktoberfest2023

arcgis-js-vscode-snippets's Introduction

arcgis-js-vscode-snippets

Visual Studio Code extension that contains a collection of snippets for common code patterns with ArcGIS Maps SDK for JavaScript.

Table of Contents

Get started

Prerequisites

To use this extension you will need to install:

  1. Visual Studio Code (version 1.35 or higher).
  2. The extension. There are two possibilities:

Usage

After installing, there are two ways to use it:

Option 1) Using built-in VS Code Intellisense:

  1. Create an empty project with an empty index.js file.
  2. Start typing one the prefix of one the available code snippets. (e.g. elev).
  3. Select the snippet by pressing Tab or Enter key.
  4. If there are values highlighted in gray, you can move between them using Tab (forward) and Shift+Tab (backwards).

Intelissense demo

Troubleshooting:
If the Intellisense doesn't work:

  • Make sure to have "editor.tabCompletion": "on" in the settings (Preferences > Open Settings(JSON))
  • If pressing Tab doesn't work then you might have several snippets with the same prefix. Press Ctrl-Space (Cmd-Space on mac) to select the one you need.

Read more about this feature in the official VSCode documentation.


Option 2) Installing the Snippet Viewer extension

This extension adds a new option to the activity bar that lets you quickly browse and insert built-in and custom snippets:

Intelissense demo

Snippets available

Prefix Description
getApi Add the CSS and JavaScript for the Esri ArcGIS Maps SDK for JavaScript from the CDN. This snippet also stubs out the package paths.
calcite Add the CSS and JavaScript for the Esri Calcite Design System from the CDN.
Prefix Description
require Load the Map and MapView modules using require
requireApiKeys Load the config, Map and MapView modules using require require
MapViewMap Create 2D MapView using a Map
SceneViewMap Create 3D SceneView using a Map.
MapViewWebMap Create 2D map using a WebMap and a portalItem.
SceneViewWebScene Create 3D map using a WebScene and a portalItem..
addLayerFromPortalItem Add a new layer to the map using a portal item id. Contains a placeholder for the portal item id.
simpleRendererProps Renders all features in a Layer with one Symbol. This snippet is usually used to set the property "renderer" of a FeatureLayer, SceneLayer, MapImageLayer, CSVLayer, GeoJSONLayer, OGCFeatureLayer, WFSLayer, or StreamLayer..
uniqueValueRendererProps Generate a unique value renderer. This snippet is usually used to set the property "renderer" of a FeatureLayer, SceneLayer, MapImageLayer, CSVLayer, GeoJSONLayer, OGCFeatureLayer, WFSLayer, StreamLayer, ImageryLayer, or ImageryTileLayer
classBreaksRendererProps Generate a ClassBreaksRenderer. This snippet is usually used to set the property "renderer" of a FeatureLayer, SceneLayer, MapImageLayer, CSVLayer, GeoJSONLayer, OGCFeatureLayer, WFSLayer, StreamLayer, ImageryLayer, or ImageryTileLayer.
sizeVisualVariableProps Set size of features based on a numeric value. Creates a SizeVariable with 2 size stops. The axis property is only used in 3D. This snippet is usually used to set the property "visualVariables[]" of a renderer.
colorVarProps Generate a ColorVariable with 2 color stops. Used to visualize features along a continuous color ramp based on the values of a numeric attribute field or an expression. This snippet is usually used to set the property "visualVariables[]" of a renderer class.
featureReductionClusterProps Generates the configuration for clustering in a MapView. This should be set on layers containing point geometry. This snippet is usually used to set the property "featureReduction" of a FeatureLayer, CSVLayer, GeoJSONLayer, WFSLayer, or OGCFeatureLayer geometry.
LabelClass2D Creates the labelingInfo for labels in a layer for 2D maps. It in normally used in the property "labelingInfo[]" of a FeatureLayer, CSVLayer, GeoJSONLayer, StreamLayer, OGCFeatureLayer, or WFSLayer in 2D MapViews.
LabelClass3D Creates the labelingInfo for labels in a layer for 3D maps. It is normally used in the property "labelingInfo[]" of a FeatureLayer, SceneLayer or any layyer with that property within a SceneView.
simpleMarkerSymbolProps Create a SimpleMarkerSymbol for rendering 2D Point geometries with a simple shape and color in either a MapView or a SceneView, but for 3D it is recommended to use PointSymbol3D. This snippet is usually used to set the property "symbol" of renderers or individual graphics..
pictureMarkerSymbolProps Create a PictureMarkerSymbol, allowing custom image-based markers for points on maps.
simpleLineSymbolProps Create a SimpleLineSymbol for rendering 2D polyline geometries in a 2D or 3D view, but for 3D it is recommended to use LineSymbol3D. It can be used in several properties like "symbol" of renderers or individual graphics, but also "outline" of marker and fill symbols.
simpleFillSymbolProps Create a SimpleFillSymbol for rendering 2D polygon geometries in a 2D or 3D view, but for 3D it is recommended to use PolygonSymbol3D. It can be filled with a solid color, or a pattern. This snippet is usually used to set the property "symbol" of renderers or individual graphics..
pictureFillSymbolProps CPictureFillSymbol uses an image in a repeating pattern to symbolize polygon features in a 2D MapView. patterns for polygons. This snippet is usually used to set the property "symbol" of renderers or individual graphics.
pointSymbol3dIconProps Generate PointSymbol3D with a IconSymbol3DLayer in a SceneView. Available shapes: circle, square, cross, x, kite, and triangle. This snippet is usually used to set the property "symbol" of renderers or individual graphics.
lineSymbol3DProps Generate LineSymbol3D with a LineSymbol3DLayer in a SceneView. This snippet is usually used to set the property "symbol" of renderers or individual graphics.
lineSymbol3DPathProps Generate LineSymbol3D with a PathSymbol3DLayer. Renders Polyline geometries by extruding a 2D profile along the line. This snippet is usually used to set the property "symbol" of renderers or individual graphics.
meshSymbol3DProps Generate MeshSymbol3D with a FillSymbol3DLayer in a SceneLayer in a SceneView. This snippet is usually used to set the property "symbol" of renderers or individual graphics.
waterSymbol3dLayerProps WaterSymbol3DLayer is used to render Polygon geometries as realistic, animated water surfaces, therefore it can only be used inside a PolygonSymbol3D. This snippet is usually used to set the property "symbol" of renderers or individual graphics.
polygonSymbol3DExtrudeProps Generate PolygonSymbol3D with a ExtrudeSymbol3DLayer to be used in a SceneView. It render polygon geometries by extruding them upward from the ground, creating a 3D volumetric object. This snippet is usually used to set the property "symbol" of renderers or individual graphics.
edges3DProps Add edge rendering visualization to existing symbols. Can only be applied to "edges" property of FillSymbol3DLayer on MeshSymbol3D or ExtrudeSymbol3DLayer on PolygonSymbol3D.
callout3DSmallProps Generates a Callout3D with a verticalOffset for a city scale level and the callout property. They should be set on the property "callout" of PointSymbol3D or LabelSymbol3D.
callout3DLargeProps Generates a Callout3D with a verticalOffset for a world scale level and the callout property. They should be set on the property "callout" of PointSymbol3D or LabelSymbol3D.
elevationInfoProps Specifies how features are placed on the vertical axis (z). This snippets should be used to set the property "elevationInfo" of a FeatureLayer, CSVLayer, WFSLayer, SceneLayer, StreamLayer, GeoJSONLayer, IntegratedMeshLayer, etc.
sceneViewEnvironmentProps Creates an environment object for changing the background of a scene. This snippet is usually used to set the property "environment" of the SceneView.
basemapsWithAPIKeys List all available map styles to be used without API keys. Use of these basemaps requires an ArcGIS Developer subscription or a valid ArcGIS Online organizational subscription
basemapsWithoutAPIKeys List all available map styles to be used without API keys. Use of these basemaps requires an ArcGIS Developer subscription or a valid ArcGIS Online organizational subscription
Prefix Description
map Import the map and map view modules then create a new Map and MapView. Contains placeholders for basemap, center and zoom.
scene Import the map and scene view modules then create a new Scene and Scene view. Contains a placeholder for the basemap
webmap Import the WebMap and MapView modules and create a new MapView from a web map id. Contains a placeholder for the web map id and map container.
webscene Import the WebScene and SceneView modules and create a new SceneView from a portal item id. Contains a placeholder for the item id and map container.
addLayerFromPortalItem Add a new layer to the map from an ArcGIS Online or Enterprise portal item. Contains a placeholder for the portal item id.
simple Generates a SimpleRenderer. Contains a placeholder for the symbol.
uniqueValue Generates a UniqueValueRenderer. Contains a placeholder for the field, the symbol and it generates a uniqueValueInfos array with placeholers for value, symbol and label for the legend.
classBreaks Generates a ClassBreaksRenderer. Contains a placeholder for the field, the default symbol and it generates a classBreakInfos array with placeholers for minValue, maxValue, symbol and label for the legend.
dotDensity Generates a DotDensityRenderer. Contains a placeholder for the dotValue, the unit, the field, the color and the label.
sizeVar Creates a SizeVariable with 2 size stops. The axis property is only used in 3D. It contains placeholders for field, normalizationField, the legend title and the size stop values.
colorVar Creates a ColorVariable with 2 color stops. It contains placeholders for field, normalizationField, the legend title and the color stop values.
clusterConfig Generates the configuration for clustering in a MapView. This should be set on layers containing point geometry.
labeling2d Creates the labelingInfo for labels in a MapView.
labeling3d Creates the labelingInfo for labels in a SceneView.
sms Creates a SimpleMarkerSymbol in a MapView. Contains placeholder for style.
pms Creates a PictureMarkerSymbol in a MapView.
sls Creates a SimpleLineSymbol in a MapView. Contains placeholder for style, cap and join.
sfs Creates a SimpleFillSymbol in a MapView. Contains placeholder for style.
pfs Creates a PictureFillSymbol in a MapView.
iconPoint3d Creates a PointSymbol3D with IconSymbol3DLayer in a SceneView. Contains placeholders for primitive, color and size.
objectPoint3d Creates a PointSymbol3D with ObjectSymbol3DLayer in a SceneView. Contains placeholders for primitive, color, height, depth and width.
line3d Creates a LineSymbol3D with a LineSymbol3DLayer in a SceneView. Contains placeholders for color and size.
path3d Creates a LineSymbol3D with a PathSymbol3DLayer in a SceneView. Contains placeholders for profile, color, width, height, join, cap, anchor and profileRotation.
fillPolygon3d Creates a PolygonSymbol3D with a FillSymbol3DLayer in a SceneView. Contains placeholders for style, material color and outline color.
waterSymbol3dLayer Creates a PolygonSymbol3D with a WaterSymbol3DLayer in a SceneView. Contains placeholder for waterbodySize and waveStrength.
extrudePolygon3d Creates a PolygonSymbol3D with an ExtrudeSymbol3DLayer in a SceneView. Contains placeholders for material color and size.
fillMesh3d Creates a MeshSymbol3D with a FillSymbol3DLayer in a SceneView. Contains placeholder for color.
sketchEdges Creates SketchEdges3D that can be applied to a FillSymbol3DLayer. Contains placeholders for the color, the size and the extensionLength.
soildEdges Creates SolidEdges3D that can be applied to a FillSymbol3DLayer. Contains placeholders for the color and the size.
calloutSmall Generates the verticalOffset for a city scale level and the callout property. They should be set on PointSymbol3D or LabelSymbol3D. Contains placeholders for size, color and border color.
calloutLarge Generates the verticalOffset for a globe scale level and the callout property. They should be set on PointSymbol3D or LabelSymbol3D. Contains placeholders for size, color and border color.
elevationInfo Creates an object for elevationInfo to be set on layers. Contains placeholders for mode, offset, arcade driven expression and unit.
sceneBackground Creates an environment object for changing the background of a scene. It should be set on a SceneView and it contains a placeholder for color.
Prefix Description
tsconfig Default tsconfig file
tsconfigBasic Simple tsconfig file
Prefix Description
widgetStarter Basic starter for creating an esri widget. Contains placeholders for the widget name and default CSS class name.
renderableProperty Add a renderable property. Contains placeholder for the property name.
constructor Add a constructor
reactmap Create a react map or scene component

Community snippets

Issues

If something isn't working the way you expected, please take a look at previously logged issues first. Have you found a new bug? Want to request an enhancement to an existing snippet? Suggest a new snippet or tool? Open a new issue, we'd love to hear from you.

Contributing

Esri welcomes contributions from anyone and everyone. Please see our guidelines for contributing.

Additional resources

To learn more about general use of code snippets in Visual Studio Code read Visual Studio official documentation.

If you create your own custom code snippets to work with the ArcGIS Maps SDK for JavaScript, please consider contributing to this repository or join other developers sharing their snippets.

License

Copyright 2023 Esri

The snippets are licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

A copy of the license is available in the repository's license.txt file.

Information on the ArcGIS Maps SDK for JavaScript licensing can be found here: https://developers.arcgis.com/javascript/latest/guide/licensing/.

arcgis-js-vscode-snippets's People

Contributors

andygup avatar carsonwood1 avatar dependabot[bot] avatar ekenes avatar estela-ex avatar hhkaos avatar kellyhutchins avatar libertadcc avatar marktorrey avatar priyanshu-bit avatar ralucanicola avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

arcgis-js-vscode-snippets's Issues

Add snippets for all Symbol classes

Today the extension contain just a few snippets

Snippet Description
simpleMarkerSymbol Creates a SimpleMarkerSymbol in a MapView. Contains placeholder for style.
pictureMarkerSymbol Creates a PictureMarkerSymbol in a MapView.
simpleLineSymbol Creates a SimpleLineSymbol in a MapView. Contains placeholder for style, cap and join.
simpleFillSymbol Creates a SimpleFillSymbol in a MapView. Contains placeholder for style.
pictureFillSymbol Creates a PictureFillSymbol in a MapView.

But this is just a small subset of all the Symbols.

It would be nice to have snippets for the following classes: (just the ones with the checkboxes; 21 in total)

Instead of just the properties:

{
  type: "simple-marker",
  color: [255, 255, 255, 0.25],
  size: 12,
  style: "circle",
  outline: {
    width: 1,
    color: [255, 255, 255, 1]
  }
}

/* Snippet
 "SimpleMarkerSymbol": {
    "body": [
      "{",
      "\ttype: \"simple-marker\",",
      "\tcolor: [255, 255, 255, 0.25],",
      "\tsize: 12,",
      "\tstyle: \"${1|circle,square,cross,x,diamond,triangle,path|}\",",
      "\toutline: {",
      "\t\twidth: 1,",
      "\t\tcolor: [255, 255, 255, 1]",
      "\t}",
      "}"
    ],
    "description": "Create a SimpleMarkerSymbol",
    "prefix": "simpleMarkerSymbol"
  }
*/

I would suggest something like:

new SimpleMarkerSymbol({
  type: "simple-marker", // required only when autocasting
  color: [255, 255, 255, 0.25],
  size: 12,
  style: "circle",
  outline: {
    width: 1,
    color: [255, 255, 255, 1]
  }
})

/* Snippet
"": {
"prefix": "",
"body": [
	"new SimpleMarkerSymbol({",
	"\ttype: \"simple-marker\", // required only when autocasting",
	"\tcolor: [255, 255, 255, 0.25],",
	"\tsize: 12,",
	"\tstyle: \"${1|circle,square,cross,x,diamond,triangle,path|}\",",
	"\toutline: {",
	"\t\twidth: 1,",
	"\t\tcolor: [255, 255, 255, 1]",
	"\t}",
	"})",
],
"description": ""
}
*/

Note: I think these are all symbols. Checking the symbol builder gallery I think I haven't left anything out... ๐Ÿ˜…

Does it make sense @kellyhutchins ? // cc: @RalucaNicola

Enhance snippets builder

I think we can improve the snippet builder by:

  • Increase height of body and description fields (calcite)
  • Adding checkboxes to be able to select the language snippet scope. It should include the following language identifiers: javascript (JavaScript), json (JSON), css (CSS), html (HTML), scss (SCSS), typescript (TypeScript), typescriptreact (TypeScrip JSX).
  • Been able to copy generated snippet to clipboard using a copy-to-clipboard button
  • Add button to import snippet (form VS Code)

Update extension icon

Currently we use a default esri icon. This issue is to identify and replace it with a more meaningful icon. Once a new icon has been identified it can be updated using the icon option in package. json

Contributing guidelines

First of all, congrats for this awesome repository :), I would love to contribute but I have no previous experience developing VSCode extensions.

I'm using a Mac, so I have modified the file at ' ~/.vscode/extensions/esri.arcgis-jsapi-snippets-1.1.2/snippets/javascript.json' but I don't know how I can test if it's properly working. How do I do it? Do I need to refresh/reload the extension?

Thanks!!

Note: I would be nice to include the readme / contributing.md simple instructions on how to do it.

Unknown language

If I go to "Help > Toggle Developer Tools" and then open up a VS code project and then open package.json, I see this error:

[Esri.arcgis-jsapi-snippets]: Unknown language in `contributes.arcgis-jsapi-snippets.language`. Provided value: typesccript

Snippet "description" conventions

Which should be the conventions about the snippet description?

2021-08-05_11-49-54

Screenshot 2021-08-05 at 12 14 16

Ideas/questions about how description should be defined:

  • Q1: It should be a proper description of what the snippet does, right?
    A: I would say yes, and reuse text from the API reference whenever possible.

  • Q2: If it is a snippet related to a class/module, do we recommend including the path to it?
    A: I would say yes (for now, the AMD Module path), but at the end probably, something like: Convert a geometry from Web Mercator units (wkid: 3857) to geographic units (wkid: 4326). Uses: esri/geometry/support/webMercatorUtils.

Snippet "body" conventions

Hello again!,

Sorry I know this issue is long, but I wanted to share with you some doubts that have arisen while I was creating new snippets and my opinion about them.

As mentioned in the previous issue, I think it would be good if we could try to reach an agreement to define minimum conventions to facilitate the contributions and make them as heterogeneous as possible.

Q0) Do we use \t instead of spaces?

{
  "tsconfig-basic": {
    "prefix": "tsConfigBasic",
    "body": [
      "{",
      "\t\"compilerOptions\": {",
      "\t\t\"module\": \"amd\",",
      "\t\t\"sourceMap\": true,",
      "\t\t\"target\": \"es2019\",",
      "\t\t\"esModuleInterop\": true",
      "\t}",
      "}"
    ],
    "description": "Simple TS Config"
}

or

{
  "tsconfig-basic": {
    "prefix": "tsConfigBasic",
    "body": [
      "{",
      "  \"compilerOptions\": {",
      "    \"lib\": [\"dom\", \"es2015.promise\", \"es5\"],",
      "    \"module\": \"amd\", // output files as AMD modules",
      "    \"sourceMap\": true,",
      "    \"target\": \"es5\",",
      "    \"esModuleInterop\": true",
      "  }",
      "}",
   ],
  "description": "Simple TS Config"
}

A: Yes, I think we should if we want to be more friendly to different tab configurations ๐Ÿ˜„

Q1) Then snippet should contain a new class initialization, its constructor properties, or both?

Ex: simpleMarkerSymbol snippet:

new SimpleMarkerSymbol({
    color: [255, 255, 255, 0.25],
    size: 12,
    style: "circle",
    outline: {
        width: 1,
        color: [255, 255, 255, 1]
    }
})

or

{
    type: "simple-marker",
    color: [255, 255, 255, 0.25],
    size: 12,
    style: "circle",
    outline: {
        width: 1,
        color: [255, 255, 255, 1]
    }
}

A: In my opinion we could add both (and call them something like simpleMarkerSymbol, simpleMarkerSymbolProps) or simply leave the second one. But in that case, I would add the Class name and the module path in the description.


Q2) When creating a new class, do we also assign it to a variable?

Ex: featureLayer snippet:

new FeatureLayer({
    url: "service-url"
    blendMode "service-url":
    effect: FeatureEffect
});

or

const fl = new FeatureLayer({
    url: "service-url"
    blendMode "service-url":
    effect: FeatureEffect
});

A: I think I would remove the variable. But I think it is a minor thing.


Q3) Should we avoid adding multiple expressions in one snippet?.

Ex: webmap snippet:

const webmap = new WebMap({
    portalItem: {
        id: "webmap_id"
    }
});

// Is this necessary?
const view = new MapView({
    container: "viewDiv",
    map: webmap
});

or featureLayer snippet:

const fl = new FeatureLayer({
    url: "service-url"
    blendMode "service-url":
    effect: FeatureEffect
});

// Is this necessary?
map.add(fl);

or disableNavigation snippet:

view.when(view => {
    const stopEvtPropagation = event => {
        event.stopPropagation();
    }

    // Are all these necessary?
    view.on(["mouse-wheel", "double-click", "drag"], stopEvtPropagation);
    view.on("double-click", ["Control"], stopEvtPropagation);
    view.on("drag", ["Shift"], stopEvtPropagation);
    view.on("drag", ["Shift", "Control"], stopEvtPropagation);
    
    view.on("key-down", function (event) {
        const prohibitedKeys = ["+", "-", "Shift", "_", "=", "ArrowUp", "ArrowDown", "ArrowRight", "ArrowLeft"];
        const keyPressed = event.key;
        if (prohibitedKeys.indexOf(keyPressed) !== -1) {
            event.stopPropagation();
        }
    });
    
    return view;
});

A: I think snippets should be as short as possible. If it is to help init a layer we should only do the init and nothing else. In some cases snippets like disable mapview navigation will be larger.


Q4) Do we allow comments?

Ex: queryLayer snippet:

myLayer  // queries all features in the layer
    .queryFeatures().then(results => {
        // queries features and returns a FeatureSet
    })
    .queryExtent().then(results => {
        // queries features returns extent of features that satisfy query
    })
    .queryFeatureCount().then(results => {
        // queries features and returns count of features
    })
    .queryObjectIds().then(results => {
        // queries features and returns objectIds array of features
    })

A: I think it is OK to add comments


Q5) When instantiating a new class, do we add only required fields, the most common ones, all?

E.x: popupTemplate snippet:

Note: do we use comments to indicate which are required? What do we do when none is required?

{
    outFields: ["*"],
    title: "Value: {attribute}",
    id: "myId",
    className: "esri-icon-zoom-out-magnifying-glass",
    content: [popupContent],
    fieldInfos: [fieldInfo],
    expressionInfos: [expressionInfo],
    actions: [ActionButton],
    returnGeometry: true
}

A: I don't have a clear answer to this. I would probably add the most used ones with a // recommended comment or similar.


Q6) When the property expects another class but supporting autocasting, what do we do?. Add a sample or place the snippet name?

E.x: heatmapRenderer snippet:

new HeatmapRenderer({
    field: "crime_count",
    colorStops: [
        { ratio: 0, color: "rgba(255, 255, 255, 0)" },
        { ratio: 0.2, color: "rgba(255, 255, 255, 1)" },
        { ratio: 0.5, color: "rgba(255, 140, 0, 1)" },
        { ratio: 0.8, color: "rgba(255, 140, 0, 1)" },
        { ratio: 1, color: "rgba(255, 0, 0, 1)" }
    ],
    minPixelIntensity: 0,
    maxPixelIntensity: 5000
})

or

new HeatmapRenderer({
    field: "crime_count",
    colorStops: HeatmapColorStop[],
    minPixelIntensity: 0,
    maxPixelIntensity: 5000
})

A: I prefer the snippet name


Q7) When a property can hold different value types, should we add a placeholder to show all possible inputs?

E.x. PopupTemplate properties:

Name Type
content Content[]|String|Function|Promise
title String|Function|Promise
... ...

Do we do something like this?

{
    "prefix": "popupTemplate",
    "body": [
      "{",
      "\toutFields: [\"*\"],",
      "\ttitle: ${1|\"Value: {attribute}\",function(){}|},",
      "\tid: ${2:\"myId\"},",
      "\tclassName: \"${3:esri-icon-zoom-out-magnifying-glass}\",",
      "\tcontent: ${4|[popupContent],\"<p>Content</p>\",function(){}|},",
      "\tfieldInfos: [fieldInfo],",
      "\texpressionInfos: [expressionInfo],",
      "\tactions: [ActionButton],",
      "\treturnGeometry: ${5|true,false|}",
      "}"
    ],
    "description": "Create an instance of esri/PopupTemplate. Describe popup content"
}

A: I think it is nice to provide all possible input types, knowing that it might not always be up-to-date. Knowing that in case of been using @types/arcgis-js-api it might be kind of duplcated (but it still can add some value like specify the value that needs to be returned by the function, or the sintax to use in the string can referer to geometry fields:
2021-07-19_13-39-19


Q8) How do we create snippets for inherited methods

Ex: method fromJSON() inherited in the SimpleRenderer, UniqueValueRenderer, HeatmapRenderer, etc.

Do we do something like this?:

${1|Simple,UniqueValue,ClassBreaks,Dictionary,DotDensity,Heatmap|}Renderer.fromJSON(json)

A: to make them generic I would try to do so.

Q9) Do we allow snippets for enums?

Ex:

  • rendererTypes: "class-breaks"|"dictionary"|"dot-density"|"heatmap"|"simple"|"unique-value"
  • basemapStyle: arcgis-imagery,arcgis-imagery-standard,arcgis-imagery-labels,arcgis-light-gray,arcgis-dark-gray,arcgis-navigation,arcgis-navigation-night,arcgis-streets,arcgis-streets-night,arcgis-streets-relief,arcgis-topographic,arcgis-oceans,osm-standard,osm-standard-relief,osm-streets,osm-streets-relief,osm-light-gray,osm-dark-gray,arcgis-terrain,arcgis-community,arcgis-charted-territory,arcgis-colored-pencil,arcgis-nova,arcgis-modern-antique,arcgis-midcentury,arcgis-newspaper,arcgis-hillshade-light,arcgis-hillshade-dark
  • symbolTypes: "simple-marker"|"picture-marker"|"simple-line"|"simple-fill"|"picture-fill"|"text"|"shield-label-symbol"|"point-3d"|"line-3d"|"polygon-3d"|"web-style"|"mesh-3d"|"label-3d"|"cim"
  • ...

A: I think I would allow them with the suffix "enum". Something like rendererTypesEnum, basemapsEnum, symbolTypesEnum, ...

Enhance snippets to work with basemaps (using API keys) & JS SDK 4.x

Check existing issues

Snippet prefix

"require" and "map"

Proposal

1) map enhance proposal

The map prefix adds:

const map = new Map({
        basemap: "arcgis-imagery"
      });
      const view = new MapView({
        container:"viewDiv",
        map:map,
        zoom:  4,
        center: [15,65]
      });

Following our conventions and having to remove variable declaration, I would replace it using autocasting and changing the prefix to MapView to have something like this (I have replace the basemap selector with to prefixes of the two snippets to the the different basemap enums):

map-snippet.mp4

My proposed snippets:

"Create MapView using a Map": {
  "prefix": "MapView",
  "body": [
    "new MapView({",
    "\tcenter: ${1:[15, 65]},",
    "\tcontainer: \"${2:viewDiv}\",",
    "\tmap: {",
    "\t\tbasemap: ${3:basemapsWithAPIKeys|basemapsWithoutAPIKeys}",
    "\t},",
    "\tzoom: ${4:4}"
    "});",
  ],
  "description": "Create MapView using a Map"
},
"Basemaps with API keys": {
  "prefix": "basemapsWithAPIKeys",
  "body": [
    "\"${1|arcgis-imagery,arcgis-imagery-standard,arcgis-imagery-labels,arcgis-light-gray,arcgis-dark-gray,arcgis-navigation,arcgis-navigation-night,arcgis-streets,arcgis-streets-night,arcgis-streets-relief,arcgis-topographic,arcgis-oceans,osm-standard,osm-standard-relief,osm-streets,osm-streets-relief,osm-light-gray,osm-dark-gray,arcgis-terrain,arcgis-community,arcgis-charted-territory,arcgis-colored-pencil,arcgis-nova,arcgis-modern-antique,arcgis-midcentury,arcgis-newspaper,arcgis-hillshade-light,arcgis-hillshade-dark|}\"",
  ],
  "description": "Basemaps enums to be used with API keys"
},
"Basemaps without API keys": {
  "prefix": "basemapsWithoutAPIKeys",
  "body": [
    "${1|satellite,hybrid,oceans,osm,terrain,dark-gray-vector,gray-vector,streets-vector,streets-night-vector,streets-navigation-vector,topo-vector,streets-relief-vector|}",
  ],
  "description": "Basemaps enums to be used without API keys"
}

The same thing would apply to scene


UPDATE: dismiss this one

2) require enhance proposal

require snippets adds:

require(["esri/Map", "esri/views/MapView","dojo/domReady!"],function(Map, MapView){
      
  });

dojo/domReady! which if I'm not wrong is for the JS SDK 3.x, right? In 4.x it returns a:

Failed to load resource: the server responded with a status of 404 ()
4.27:31 Error: scriptError: https://js.arcgis.com/4.27/dojo/domReady.js
    at n (4.27:6:46)
    at HTMLScriptElement.<anonymous> (4.27:30:44)

So, considering 3.x will be retired in July 2024, we should remove the dojo/domReady.

I would also include to add a require and a requireApiKeys

require([
	"esri/config",
	"esri/Map", 
	"esri/views/MapView"
], function(
	esriConfig,
	Map, 
	MapView
){
      esriConfig = "${1:YOUR_API_KEY}";
});

What do you think @kellyhutchins ?

Snippet proposal: Find a layer by it's name

I took the idea from this script that Maarten from Esri Netherlands published on its CoolScripts repo.


Prefix: findLayer
Description:
Snippet:

const fl = view.map.layers.find( l => l.title === "${1:LayerTitle}");

Code:

"Find a layer by it's name": {
    "prefix": "findLayer",
    "body": [
	"const fl = view.map.layers.find( l => l.title === \"${1:LayerTitle}\");",
    ],
    "description": ""
}

๐ŸŽƒ ๐—›๐—ฎ๐—ฐ๐—ธ๐˜๐—ผ๐—ฏ๐—ฒ๐—ฟ๐—ณ๐—ฒ๐˜€๐˜ ๐——๐—ฒ๐˜๐—ฎ๐—ถ๐—น๐˜€ ๐—ณ๐—ผ๐—ฟ ๐—ฃ๐—ฎ๐—ฟ๐˜๐—ถ๐—ฐ๐—ถ๐—ฝ๐—ฎ๐—ป๐˜๐˜€ ๐Ÿ‘จโ€๐Ÿ’ป

Greetings and happy Hacktoberfest 2023!

We're thrilled that you've chosen to participate in Hacktoberfest with us! Please bear in mind that during the month of October ๐ŸŽƒ, the volume of pull requests (PRs), comments, and other interactions may be higher than usual. Therefore, we kindly ask for your patience while awaiting responses. To increase the likelihood of a successful PR, please adhere to the following guidelines:

  • Familiarize yourself with the repository by reading the README.md.
  • Review and follow all the guidelines outlined in CONTRIBUTING.md.
  • When you receive feedback on your PR, incorporate the changes into the same PR rather than creating a new one.
  • Ensure your PR has a descriptive title, as this will facilitate a smoother review process.

If you haven't already, please check out our blog article ๐Ÿ“ƒ, which contains valuable information, including a list of participating Hacktoberfest repositories and details about our contest ๐Ÿ† and rules. Additionally, consider joining our Slack channel to join in the fun, receive announcements, interact with maintainers, Esri employees, and fellow participants, and have a place to ask any questions you may have.

Mappy Hacking! ๐Ÿ—บ ๐Ÿ‘ฉโ€๐Ÿ’ป

Add snippets for all Layer classes

Today the extension contain just a one snippets

Snippet Description
addLayerFromPortalItem Add a new layer to the map from an ArcGIS Online or Enterprise portal item. Contains a placeholder for the portal item id.

But there are a lot of (Layer) types.

It would be nice to have snippets for the following classes: (38 in total)

Most of these layers have the possibility to be initialized in different ways (e.g. using source or a similar property), with a url, and/or using a portalItem. Like FeatureLayer (using: source, url, portalItem), RouteLayer (using: stops, url and portalItem, StreamLayer (webSocketUrl or url), etc.

I think the portalItem is the easiest to remember, and having addLayerFromPortalItem I don't see that very relevant. I also think using the URL is probably one of the most commons ways, but also the easiest to remember. I would say having the custom-source/client-side (for been the most complex to remember) or both (including url) if you think that should be default, would be my preference for these snippets.

Does it make sense @kellyhutchins ? // cc: @RalucaNicola

Snippets cheatsheet

What do you feel about making a printable version like this:

VSCode ES7 React/Redux snippets Cheat Sheet by frankieali4

Right now, the table in the readme doesn't look very friendly to me. I would probably organize by categories like: basics, core, geometry, layers, renderers, popup, smartmapping, ... maybe even grouping using some color to differentiate those snippets only for 2D or 3D elements from the common ones.

If you think it might be worthy I don't mind making the first sketch in a collaborative tool like Google Drawing on which we can iterate.

Snippet "name" conventions

Which should be the conventions about the snippet name?

2021-08-05_11-49-33

Just to keep in mind, when you are typing a lot of built-in snippets shows up:

Screenshot 2021-08-05 at 11 51 45

Important note: names have to be unique.

Ideas/questions about how names should be defined:

  • Q1) Does it make sense to add something like Esri JS API? to differentiate (from others?).
    A: I don't think so, it would make it very long.

  • Q2) Do we allow spaces or use camelcase? (E.g. List map styles vs ListMapStyles).
    A: I think we should allow spaces.

  • Q3) Do we recommend not to use more than... 5? words. (to describe what it does)
    A: I would say yes.

  • Q4) We just split words? (E.g. createMap to Create Map).
    A: I would split and start with capitals.

  • Q5) Do we use the same name but with 2D & 3D suffixes when there are equivalent snippets for 2D and 3D?.
    A: I think we should.

Add basic snippets

In addition to the existing snippets, which I would recommend revisiting to make them clearer (like with map)
Screenshot 2023-09-27 at 00 55 34

It would be nice adding some additional ones:

Add Snippets builder to enhance the contribution experience

Hello again!,

I wanted to share a simple interface I have built for myself to help me create new snippets. While I was doing it, I decided to make it public just in case it could help other developers too (for personal use or to contribute to this repo).

So I just wanted to share it with you:

VS Code snippets builder

If you think it can make sense to host the app on this repo, I can finish/clean it a little, remove my repo and do a pull request to this one.

Cheers!

Snippet proposal: Load a MapView (2D)

I would add a snippet to help instantiate a MapView Class in *.js files (this issue was opened with the help of the snippet building)


Prefix: MapView
Description: Create an instance of esri/views/MapView
Snippet:

const view = new MapView({
	container: "${1:viewDiv}",
	map: ${2:map},
	zoom: ${3:4},
	center: [${4:15,65}]
});

Code:

"Load a MapView (2D)": {
    "prefix": "MapView",
    "body": [
	"const view = new MapView({",
	"\tcontainer: \"${1:viewDiv}\",",
	"\tmap: ${2:map},",
	"\tzoom: ${3:4},",
	"\tcenter: [${4:15,65}]",
	"});",
    ],
    "description": "Create an instance of esri/views/MapView"
}

Programmatically create UI/cheat sheet to explore snippets

Problem

As I mentioned in the Snippet cheatsheet issue. Maintain the table of snippets available manually is:

  • It is more time-consuming:
    • Require an additional check on every PR to ensure the entry has been added in the table
    • Require contributors to modify the readme
  • Prone to error/inconsistencies:
    • Mismatch between: prefixes and descriptions (table and snippets file)
  • Not very usable:
    • The table is not intuitive to explore, even in alphabetical order (other programming cheat sheets group snippets, and use multiple columns). This affect users, but also for maintainers/contributors trying to understand if a code snippet already exists.

This also apply to the one I made with cheatography.com. But I think is worth to have a mechanism that can ensure it is always updated.

Proposal

I think making a web interface should be pretty simple. I have been testing, and I think we can add "custom properties" to the custom snippets:
2023-09-26_12-40-35

That, way we could create properties like:

What do you think? I envision something a simple serverless SPA, like this:

Screenshot 2023-09-26 at 14 18 41

Snippet "prefix" convetions

I see there are many acronyms sms, sls, sfs, ... I think it would be also nice to add the extended version for developers not so familiar with our acronyms, something like SimpleMarkerSymbol (sms):

{
"SimpleMarkerSymbol": {
    "body": [
      "{",
      "\ttype: \"simple-marker\",",
      "\tcolor: [255, 255, 255, 0.25],",
      "\tsize: 12,",
      "\tstyle: \"${1|circle,square,cross,x,diamond,triangle,path|}\",",
      "\toutline: {",
      "\t\twidth: 1,",
      "\t\tcolor: [255, 255, 255, 1]",
      "\t}",
      "}"
    ],
    "description": "Create a SimpleMarkerSymbol",
    "prefix": "SimpleMarkerSymbol (sms)"
  },

This way it still matches with sms, but also with sym, marke, ...:

Screenshot 2021-06-16 at 17 40 33
Screenshot 2021-06-16 at 17 40 42
Screenshot 2021-06-16 at 17 41 07

Update: This has been added to the description
I would also add in the name, the path to classes. Instead of just SimpleMarkerSymbol use symbols/SimpleMarkerSymbol:
...

Does any of these ideas make sense to you? ๐Ÿ˜„

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.