Hi All,
I'm going to set the preview HTML as same as the text symbol show on the map. I notice that there is a method renderPreviewHTML. However, the result is under expectation. Here is the code and result.
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no" />
<title>Test Page</title>
<style>
html,
body,
#viewDiv {
padding: 0;
margin: 0;
height: 100%;
width: 100%;
}
#symbol-preview {
position: absolute;
right: 100px;
top: 100px;
width: 150px;
height: 50px;
border: 1px solid black;
background-color: white;
}
</style>
<link rel="stylesheet" href="https://js.arcgis.com/4.26/esri/themes/light/main.css">
<script src="https://js.arcgis.com/4.26/"></script>
<script>
require([
"esri/Map",
"esri/views/MapView",
"esri/Graphic",
"esri/symbols/TextSymbol",
"esri/symbols/support/symbolUtils"],
function(Map, MapView, Graphic, TextSymbol, symbolUtils) {
const map = new Map({
basemap: "streets"
});
const view = new MapView({
map: map,
center: [-117.1947900, 34.0572650], // Longitude, latitude
zoom: 13, // Zoom level
container: "viewDiv" // Div element
});
const markerSymbol = {
type: "simple-marker",
color: "blue",
size: "8px",
};
const graphic = new Graphic({
attributes: {
"Sequence": 5
},
geometry: {
type: "point",
longitude: -117.1947900,
latitude: 34.0572650
},
symbol: {
type: "simple-marker",
color: "blue",
size: "8px",
}
});
view.graphics.add(graphic);
// preview symbol
const textSymbol = new TextSymbol({
color: [255, 165, 0],
haloColor: [0, 0, 0],
haloColor: [255, 255, 255],
haloSize: "2px",
text: "Esri",
backgroundColor: [0, 165, 165],
borderLineSize: "1px",
borderLineColor: [0, 0, 0],
font: {
size: 20,
family: "Josefin Slab",
weight: "bold"
}
});
symbolUtils.renderPreviewHTML(textSymbol, {
node: document.getElementById("symbol-preview"),
size: 20
});
const textGraphic = new Graphic({
geometry: {
type: "point",
longitude: -117.1947900,
latitude: 34.0572650,
},
symbol: textSymbol
});
view.graphics.add(textGraphic);
});
</script>
</head>
<body>
<div id="viewDiv"></div>
<div id="symbol-preview"></div>
</body>
</html>
My question is: Is this a bug on renderPreviewHTML or how to make the text symbol show on map same as in preview?
Thanks,
Leo