Any way to use local image file instead of embedded resource image for PictureMarkerSymbol?

1500
5
03-10-2018 06:44 AM
PeterRobbins
New Contributor

All. First off, hello. (First time post. I've been using the sdk for a few months now and I just want to say thank you for a great set of tools.)

Scenario:

I've successfully used the examples for PictureMarkerSymbol Class  to show a icon at the location the user tapped on the map, but I would prefer to use local image instead of embedded resource for image files. Does anyone have an example of using PictureMarkerSymbol Class with a local image file they would be willing to share? I want the app to be able to use the appropriate size marker based upon resolution, and this use of embedded resource via the assembly I do not believe will auto resize based upon the iOS or Android screen resolution. Is there perhaps another stream method I'm just being naive about and could use in place of what is in the examples in the class api info?

(Sidenote: I was able to position the marker appropriately at the exact point of tapping by settings its height and width manually, and then using height/2 to position the bottom of the map marker right at the point of tapping. I'm happy with that result)

Long Story Short:

I've been able to place marker, but I don't know how to appropriately handle resizing the image (or using alternative images) based upon the screen size in Android and iOS. 

Thanks, Peter R.

0 Kudos
5 Replies
NagmaYasmin
Occasional Contributor III

PicturemarkerSymbol takes Uri in the constructor, so you could point out any image file that is locally stored as below:

PictureMarkerSymbol carSymbol = new PictureMarkerSymbol(new Uri(@"C:\img1.jpg"));

Hope that helps.

PeterRobbins
New Contributor

Thank you for reply. This may be a method of getting the local file instead of via embedded resource, but I think my overall question is whether GetManifestResourceStream in their example code will choose an appropriately sized version of a given image based upon the common structure of /Resources/myimagefile.png and /Resources/myimagefile@2.png for IOS, and Resources/drawable/myimagefile.png and other sub-directories such as  /Resources/drawable-ldpi/myimagefile.png, /Resources/drawable-hdpi/myimagefile.png, etc for Android.

So, my original subject line is possibly not the best here. I'm just trying to figure out what method to use to still be able to have different versions of the map marker for different resolution screens show up properly.

0 Kudos
dotMorten_esri
Esri Notable Contributor

You'd have to use the correct path to pick the right image resolution yourself. However it's a good idea to automatically do this, and I'll add it to the backlog.

PeterRobbins
New Contributor

If you are taking requests : ), allowing for the automatic offsetting of the image to line up at the map click point would be a nice option as well. For example, map markers, more often than not, you'd want to automatically align it to the center & bottom of the marker. Also, when I was testing the tutorial code out, I noticed that it does not appear to automatically provide the Width and Height of the streamed image from the assembly (though it hints this would be auto set if none were manually forced)

So... for example, I had to force the Height and Width explicitly, and then I was able to do:

pinSymbol.Height = 22;

pinSymbol.Width = 22;

pinSymbol.OffsetY = pinSymbol.Height / 2;

Without setting them explictly, they were always resolving as 0 height and width for that calculation.

Just further food for thought. Thank you for a very nice API. It's been nice to work with. Also thank you for considering more automatic handling that lines up with other xamarin forms methods of image resolution choices.

0 Kudos
dotMorten_esri
Esri Notable Contributor

If you don't set the width/height it'll default to the width/height of the raw image source. So as you found "0" means "auto". If you use high-res images, you should definitely set the width/height explicitly, as we assume the images are meant for 96dpi otherwise (that might change if we can automatically do the @2 scaling).

I'm not clear on what you mean by requesting a way to offset the image, when you then show how to do it right after, indicating that it is already there