Select to view content in your preferred language

get initialExtent instead of fullextent

269
2
Jump to solution
08-28-2024 03:33 AM
LionelGOUBET
Regular Contributor

I don't understand why the initial extent is not available to build a map on a MapImageLayer ? only fullextent is available

var mapImageLayer = new MapImageLayer({
url: "URL_DU_MAP_IMAGE_LAYER"
});


mapImageLayer.load().then(function() {
// Obtenir l'étendue initiale du MapImageLayer
var initialExtent = mapImageLayer.initialExtent;

console.log("Étendue initiale du MapImageLayer : ", initialExtent);

// Créer la vue de la carte en utilisant l'étendue initiale
var map = new Map({
basemap: "streets",
layers: [mapImageLayer]
});

var view = new MapView({
container: "viewDiv", // ID de l'élément HTML où la carte sera affichée
map: map,
extent: initialExtent
});
}).catch(function(error) {
console.error("Erreur lors du chargement du MapImageLayer : ", error);
});

 

the only solution is used the rest api with ?f=json

Thanks for your explanation

 

 

 

 

 
0 Kudos
1 Solution

Accepted Solutions
JoelBennett
MVP Regular Contributor

The MapImageLayer class doesn't expose an initialExtent property, but the value can still be retrieved from its sourceJSON property.  See line 7 below, which also uses Extent.fromJSON:

var mapImageLayer = new MapImageLayer({
	url: "URL_DU_MAP_IMAGE_LAYER"
});

mapImageLayer.load().then(function() {
	// Obtenir l'étendue initiale du MapImageLayer
	var initialExtent = Extent.fromJSON(mapImageLayer.sourceJSON.initialExtent);

	console.log("Étendue initiale du MapImageLayer : ", initialExtent);

	// Créer la vue de la carte en utilisant l'étendue initiale
	var map = new Map({
		basemap: "streets",
		layers: [mapImageLayer]
	});

	var view = new MapView({
		container: "viewDiv", // ID de l'élément HTML où la carte sera affichée
		map: map,
		extent: initialExtent
	});
}).catch(function(error) {
	console.error("Erreur lors du chargement du MapImageLayer : ", error);
});

 

View solution in original post

0 Kudos
2 Replies
JoelBennett
MVP Regular Contributor

The MapImageLayer class doesn't expose an initialExtent property, but the value can still be retrieved from its sourceJSON property.  See line 7 below, which also uses Extent.fromJSON:

var mapImageLayer = new MapImageLayer({
	url: "URL_DU_MAP_IMAGE_LAYER"
});

mapImageLayer.load().then(function() {
	// Obtenir l'étendue initiale du MapImageLayer
	var initialExtent = Extent.fromJSON(mapImageLayer.sourceJSON.initialExtent);

	console.log("Étendue initiale du MapImageLayer : ", initialExtent);

	// Créer la vue de la carte en utilisant l'étendue initiale
	var map = new Map({
		basemap: "streets",
		layers: [mapImageLayer]
	});

	var view = new MapView({
		container: "viewDiv", // ID de l'élément HTML où la carte sera affichée
		map: map,
		extent: initialExtent
	});
}).catch(function(error) {
	console.error("Erreur lors du chargement du MapImageLayer : ", error);
});

 

0 Kudos
LionelGOUBET
Regular Contributor

Thanks Joel 😀

... I missed it 🙄

0 Kudos