Hi Thomas,
your solution works great on the upper code snippet.
I integrated your solution into my whole code and realized that it still doesn't work.
I think it has something to do with the projection of my points with GeometryService and then pushing them into the layer.
Can you say where the problem is?
<script>
require([
"esri/Map",
"esri/views/MapView",
"esri/layers/FeatureLayer",
"esri/Graphic",
"esri/geometry/Point",
"esri/symbols/SimpleMarkerSymbol",
"esri/tasks/GeometryService",
"esri/tasks/support/ProjectParameters",
"esri/geometry/SpatialReference",
"esri/widgets/Compass",
"esri/widgets/BasemapGallery",
"esri/widgets/Track",
"esri/renderers/SimpleRenderer",
"esri/geometry/SpatialReference",
"esri/widgets/Search",
"esri/widgets/Expand",
"esri/widgets/LayerList",
"dojo/domReady!"
], function (Map, MapView, FeatureLayer, Graphic, Point, SimpleMarkerSymbol, GeometryService, ProjectParameters, SpatialReference, Compass, BasemapGallery, Track, SimpleRenderer, SpatialReference, Search, Expand, LayerList
) {
var geoSvc = new GeometryService({
url: 'https://utility.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer'
});
var mapZoom = 10;
var mapCenter = [10.734112, 48.174298];
var map = new Map({
basemap: "osm"
});
var view = new MapView({
center: mapCenter,
container: "viewDiv",
map: map,
zoom: mapZoom
});
var sr = new SimpleRenderer({
symbol: new SimpleMarkerSymbol({
color: [226, 119, 40],
size: "15pt",
outline: {
color: [255, 255, 255],
width: 2
}
})
});
var lyr = new FeatureLayer({
fields: [
{
name: "ObjectID",
alias: "ObjectID",
type: "oid"
}
],
objectIdField: "ObjectID",
geometryType: "point",
title: "Hundestation",
spatialReference: { wkid: 102100 },
source: [],
popupTemplate: {
title: "Title",
content: "Test"
},
minScale: 1000000,
maxScale: 1,
renderer: sr
});
lyr.createQuery = function(){
let q = lyr.__proto__.createQuery.call(lyr);
q.outFields = null;
q.where = null;
return q;
}
var sizeCrownSymbol = 0;
var feature = [
new Point({
x: 4408069.551,
y: 5338730.568,
spatialReference: { wkid: 31468 }
})
];
projectPoints (geoSvc, feature, lyr, "10", "Lagebeschreibung: Kroengelände", sizeCrownSymbol);
var feature = [
new Point({
x: 4408681.069,
y: 5338984.143,
spatialReference: { wkid: 31468 }
})
];
projectPoints (geoSvc, feature, lyr, "11", "Lagebeschreibung: Holzheystraße", sizeCrownSymbol);
var feature = [
new Point({
x: 4408132.398,
y: 5339858.609,
spatialReference: { wkid: 31468 }
})
];
projectPoints (geoSvc, feature, lyr, "12", "Lagebeschreibung: Breitlehenstraße", sizeCrownSymbol);
map.add(lyr);
function projectPoints(geoSvc, geometries, lyr, primarykey, popUpAttributes, sizeCrownSymbol){
geoSvc.project({
geometries: geometries,
outSpatialReference: SpatialReference.WebMercator
}).then(geometries => {
let features = geometries.map((geometry, idx) => {
return new Graphic({
geometry: geometry,
attributes: {
objectID: idx - 1,
sizeCrownSymbol: sizeCrownSymbol
}
});
});
features.forEach(f => lyr.source.push(f));
});
}
});
</script>
Best Regards
Michael