Can I render a markerSymbol image without having to define the width and height manually?

418
4
Jump to solution
05-02-2019 12:16 PM
BrianRoscher
New Contributor III

Here is the function we currently use to add the point images onto our map:

function addGraphic() {
var point = new Point();
point.setLongitude(document.getElementById("lon").value);
point.setLatitude(document.getElementById("lat").value);

var infoTemplate = new InfoTemplate();
infoTemplate.setTitle("Population");
infoTemplate.setContent("Hi<br/>Dude!");

var markerSymbol = new PictureMarkerSymbol();
markerSymbol.setUrl(document.getElementById("picture_url").value);
//markerSymbol.setHeight(64);
//markerSymbol.setWidth(64);

map.enableMapNavigation();
var graphic = new Graphic(point, markerSymbol);
graphic.setInfoTemplate(infoTemplate);
map.graphics.add(graphic);
}

You will notice that we commented out the setHeight and setWidth lines in hopes that it would simply render the actual image in its actual height and width.

We have a Google Maps application we are migrating to ESRI.  In our application, we have a zillion little picture files that can be markerSymbol images on the map.  The heights and widths of these images are different from one another.  When I have ESRI render our images onto the map, it distorts them all into a one size fits all square.

Is there a way to make ESRI simply display an image on the map (whatever the zoom level) without distorting that image or must I manually set the width and height of each image (which is going to be a huge job to figure out the height and width of the zillions of images we have and store them in a database somewhere to have to manually set them in ESRI)?

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Brian,

   The height and width properties of the PictureMarkerSymbol have default values of 12

https://developers.arcgis.com/javascript/latest/api-reference/esri-symbols-PictureMarkerSymbol.html#...

You would  have to use JS native methods to get the images height and width.

var new_img = new Image();

new_img.onload = function() {
    var width  = this.width,
        heigth = this.height;
}

new_img.src = ""

View solution in original post

4 Replies
RobertScheitlin__GISP
MVP Emeritus

Brian,

   The height and width properties of the PictureMarkerSymbol have default values of 12

https://developers.arcgis.com/javascript/latest/api-reference/esri-symbols-PictureMarkerSymbol.html#...

You would  have to use JS native methods to get the images height and width.

var new_img = new Image();

new_img.onload = function() {
    var width  = this.width,
        heigth = this.height;
}

new_img.src = ""
BrianRoscher
New Contributor III

Hi Robert,

Thanks for posting that work around solution.  

It would be great if ESRI added an optional setting to render an image in its original size.  For example, maybe markerSymbol.setHeight(-1);   and markerSymbol.setWidth(-1)... Or maybe another markerSymbol.setSomething(true).

I just mentioned the above idea with the hopes that the developers of ESRI might read it and consider implementing this idea if it is feasible.

Thanks again for your help!

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Brain,

   Have you ever used ArcGIS Ideas‌? This is exactly what it is intended for. 

0 Kudos
BrianRoscher
New Contributor III

Thanks!  Because you showed me that link, I just posted this idea in there.

0 Kudos