Select to view content in your preferred language

Points won't show up

587
1
Jump to solution
01-06-2022 01:47 PM
Epiper40
New Contributor

I'm developing a custom widget based upon another users code that I saw on here. My problem is that the code runs and then no points show up. What am I doing wrong?

Code:

define([
'dojo/_base/declare',
'dojo/_base/html',
'dijit/_WidgetsInTemplateMixin',
"esri/geometry/Point",
'esri/SpatialReference',
'jimu/BaseWidget',
'jimu/utils',
'jimu/dijit/Message',
'dojo/_base/lang',
'dojo/on',
"dojo/dom-class",
"esri/graphic",
"esri/layers/GraphicsLayer",
"esri/tasks/ProjectParameters",
"esri/geometry/webMercatorUtils",
"jimu/portalUtils",
"esri/config",
"libs/usng/usng",
"jimu/SpatialReference/unitUtils",
"esri/map",
//"esri/views/Mapview",
"esri/symbols/PictureMarkerSymbol",
"esri/symbols/SimpleMarkerSymbol",
"esri/InfoTemplate"
],
function(
declare,
html,
_WidgetsInTemplateMixin,
Point,
SpatialReference,
BaseWidget,
utils,
Message,
lang,
on,
domClass,
Graphic,
GraphicsLayer,
ProjectParameters,
webMercatorUtils,
portalUtils,
esriConfig,
usng,
unitUtils,
Map,
//MapView,
PictureMarkerSymbol,
SimpleMarkerSymbol,
InfoTemplate
){
var clazz = declare([BaseWidget], {
// postCreate: function() {
// this.inherited(arguments);
// console.log('postCreate');
// },

startup: function() {
var locations = ["-90.2594, 38.6128", "-90.2704, 38.6290", "-90.2913, 38.6350"];
var map = new Map("map", {
basemap: "topo-vector",
center: [-25.312, 34.307],
zoom: 2
});
//map.on("load", initToolbar);
/*var view = new MapView({
container: "viewDiv",
map: map,
center: [0,0], // longitude, latitude
zoom: 6
});*/
var gl = new GraphicsLayer();
map.addLayer(gl);
for(i=0; i<locations.length; i++){

//var s = new PictureMarkerSymbol('https://webwin-portal.tgis.suprtek.com/portal/home/item.html?id=aa6642331cfa47c9ae112af1f0cad07d', 24, 24);
var simpleMarkerSymbol = {
type: "simple-marker",
color: [46, 204, 113 ], // Green
outline: {
color: [255, 255, 255], // white
width: 5
}
};
var p = new Point(locations[i].split(",")[0],locations[i].split(",")[1]);
var it = new InfoTemplate("Attributes","Test");
var g = new Graphic(p, simpleMarkerSymbol).setInfoTemplate(it);

gl.add(g);
}
gl.show();
//map.addLayer(gl);
}
})
return clazz;
});

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
Epiper40
New Contributor

Another Developer on my team and I solved it. Here's our code so that it can help someone in the future. It relies on the url passing the point information:

define([
'dojo/_base/declare',
'dojo/_base/html',
'dijit/_WidgetsInTemplateMixin',
"esri/geometry/Point",
'esri/SpatialReference',
'jimu/BaseWidget',
'jimu/utils',
'jimu/dijit/Message',
'dojo/_base/lang',
'dojo/on',
"dojo/dom-class",
"esri/graphic",
"esri/layers/GraphicsLayer",
"esri/tasks/ProjectParameters",
"esri/geometry/webMercatorUtils",
"jimu/portalUtils",
"esri/config",
"libs/usng/usng",
"jimu/SpatialReference/unitUtils",
"esri/map",
"esri/symbols/PictureMarkerSymbol",
"esri/symbols/SimpleMarkerSymbol",
"esri/Color",
"esri/InfoTemplate"
],
function(
declare,
html,
_WidgetsInTemplateMixin,
Point,
SpatialReference,
BaseWidget,
utils,
Message,
lang,
on,
domClass,
Graphic,
GraphicsLayer,
ProjectParameters,
webMercatorUtils,
portalUtils,
esriConfig,
usng,
unitUtils,
Map,
PictureMarkerSymbol,
SimpleMarkerSymbol,
Color,
InfoTemplate
){
var clazz = declare([BaseWidget], {

startup: function() {
const urlString = window.location.href;
const pointParse = urlString.split('?')[1];
const pointParse2 = pointParse.split('&');
var locations = [];
for(i=0; i<pointParse2.length; i++)
{
const point = pointParse2[i].replace('points=', '');
console.log(point);
locations.push(point);
}

if(locations != null) {
var myMap = this.map;
var sms = new SimpleMarkerSymbol().setStyle(SimpleMarkerSymbol.STYLE_CIRCLE).setColor(new Color([255,0,0,0.5])).setSize(12);

for(i=0; i<locations.length; i++){
console.log("adding points");
var p = new Point(parseFloat(locations[i].split(",")[0]),parseFloat(locations[i].split(",")[1]), new SpatialReference({ wkid: 4326}));
var g = new Graphic(p, sms);
myMap.graphics.add(g);
}
}

}

})

return clazz;
});

View solution in original post

0 Kudos
1 Reply
Epiper40
New Contributor

Another Developer on my team and I solved it. Here's our code so that it can help someone in the future. It relies on the url passing the point information:

define([
'dojo/_base/declare',
'dojo/_base/html',
'dijit/_WidgetsInTemplateMixin',
"esri/geometry/Point",
'esri/SpatialReference',
'jimu/BaseWidget',
'jimu/utils',
'jimu/dijit/Message',
'dojo/_base/lang',
'dojo/on',
"dojo/dom-class",
"esri/graphic",
"esri/layers/GraphicsLayer",
"esri/tasks/ProjectParameters",
"esri/geometry/webMercatorUtils",
"jimu/portalUtils",
"esri/config",
"libs/usng/usng",
"jimu/SpatialReference/unitUtils",
"esri/map",
"esri/symbols/PictureMarkerSymbol",
"esri/symbols/SimpleMarkerSymbol",
"esri/Color",
"esri/InfoTemplate"
],
function(
declare,
html,
_WidgetsInTemplateMixin,
Point,
SpatialReference,
BaseWidget,
utils,
Message,
lang,
on,
domClass,
Graphic,
GraphicsLayer,
ProjectParameters,
webMercatorUtils,
portalUtils,
esriConfig,
usng,
unitUtils,
Map,
PictureMarkerSymbol,
SimpleMarkerSymbol,
Color,
InfoTemplate
){
var clazz = declare([BaseWidget], {

startup: function() {
const urlString = window.location.href;
const pointParse = urlString.split('?')[1];
const pointParse2 = pointParse.split('&');
var locations = [];
for(i=0; i<pointParse2.length; i++)
{
const point = pointParse2[i].replace('points=', '');
console.log(point);
locations.push(point);
}

if(locations != null) {
var myMap = this.map;
var sms = new SimpleMarkerSymbol().setStyle(SimpleMarkerSymbol.STYLE_CIRCLE).setColor(new Color([255,0,0,0.5])).setSize(12);

for(i=0; i<locations.length; i++){
console.log("adding points");
var p = new Point(parseFloat(locations[i].split(",")[0]),parseFloat(locations[i].split(",")[1]), new SpatialReference({ wkid: 4326}));
var g = new Graphic(p, sms);
myMap.graphics.add(g);
}
}

}

})

return clazz;
});

0 Kudos