Last active
January 4, 2020 22:02
-
-
Save ryansutc/906e380ede83d2859b20ff7be09e71b0 to your computer and use it in GitHub Desktop.
An Old ESRI Widget Hello World Sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <amd-dependency path="esri/core/tsSupport/declareExtendsHelper" name="__extends" /> | |
/// <amd-dependency path="esri/core/tsSupport/decorateHelper" name="__decorate" /> | |
import { subclass, declared, property } from "esri/core/accessorSupport/decorators"; | |
import Widget from "esri/widgets/Widget"; | |
import { renderable, tsx } from "esri/widgets/support/widget"; | |
tsx; // Reference tsx here, this will be used after compilation to JavaScript | |
const CSS = { | |
base: "esri-hello-world", | |
emphasis: "esri-hello-world--emphasis" | |
}; | |
@subclass("esri.widgets.HelloWorld") | |
class HelloWorld extends declared(Widget) { | |
//---------------------------------- | |
// firstName | |
//---------------------------------- | |
@property() | |
@renderable() | |
firstName: string = "John"; | |
//---------------------------------- | |
// lastName | |
//---------------------------------- | |
@property() | |
@renderable() | |
lastName: string = "Smith"; | |
//---------------------------------- | |
// emphasized | |
//---------------------------------- | |
@property() | |
@renderable() | |
emphasized: boolean = false; | |
// Public method | |
render() { | |
const greeting = this._getGreeting(); | |
const classes = { | |
[CSS.emphasis]: this.emphasized | |
}; | |
return ( | |
<div class={this.classes(CSS.base, classes)}> | |
<p></p> | |
{greeting} | |
</div> | |
); | |
} | |
// Private method | |
private _getGreeting(): string { | |
return `Hello, my name is ${this.firstName} ${this.lastName}!`; | |
} | |
} | |
export = HelloWorld; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8" /> | |
<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" /> | |
<title>Create a custom widget - 4.11</title> | |
<style> | |
.esri-hello-world { | |
font-family: "Helvetica Neue", sans-serif; | |
display: inline-block; | |
} | |
.esri-hello-world--emphasis { | |
font-weight: bold; | |
} | |
</style> | |
<script> | |
var locationPath = location.pathname.replace(/\/[^\/]+$/, ""); | |
window.dojoConfig = { | |
packages: [ | |
{ | |
name: "app", | |
location: locationPath + "/app" | |
} | |
] | |
}; | |
</script> | |
<script src="https://js.arcgis.com/4.11/"></script> | |
<script> | |
var widget; | |
require(["app/HelloWorld"], function(HelloWorld) { | |
var names = [ | |
{ | |
firstName: "John", | |
lastName: "Smith" | |
}, | |
{ | |
firstName: "Jackie", | |
lastName: "Miller" | |
}, | |
{ | |
firstName: "Anna", | |
lastName: "Price" | |
} | |
], | |
nameIndex = 0; | |
var widget = new HelloWorld({ | |
firstName: names[nameIndex].firstName, | |
lastName: names[nameIndex].lastName, | |
container: "widgetDiv" | |
}); | |
function changeName() { | |
widget.set(names[++nameIndex % names.length]); | |
} | |
widget.on("greeted", function(event) { | |
console.log(event); | |
}); | |
setInterval(changeName, 1000); | |
}); | |
</script> | |
</head> | |
<body> | |
<div id="widgetDiv"></div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment