Select to view content in your preferred language

Resize and Reposition Map

4834
7
03-11-2016 07:55 AM
JohnPreston
Deactivated User

I would like to resize and reposition map div and map after user clicks button. When page loads map is positioned to float right with taking up a certain % of page. I would like to reposition map to left and set size to specific #. I can move the map and resize, however the map layers do reposition in center. I'm sure I missing something. Here is my code...

onClick: function () {

$('#left_col').hide();

$('#right_col').css("float", "left");

$('#right_col').css("width", "500px");

$('#right_col').css("height", "500px");

$('#map').css("float", "left");

$('#map').css("width", "500px");

$('#map').css("height", "500px");

map.width = 1000;

map.height = 500;

map.resize();

map.reposition();

});

Tags (2)
0 Kudos
7 Replies
TyroneBiggums
Deactivated User

Your map width is 1000 but the containing map div is 500px.

0 Kudos
JohnPreston
Deactivated User

I tried making them both 500, however the map doesn't resize at all. With the code I posted the map actually resized but didn't reposition.

When I do change to both to 500, and I pan just a little the map then repositions in center (does that make sense)?

0 Kudos
TyroneBiggums
Deactivated User

Height and width are read-only for the map. Remove map.width and map.height. Your map is in a containing div, right? #right_col or #map? Just resize the containing div.

Map | API Reference | ArcGIS API for JavaScript

0 Kudos
JohnPreston
Deactivated User

I took out map.width and map.height, now map doesn't resize. The map is contained in #map, the #map div is contained in #right_col.

0 Kudos
TyroneBiggums
Deactivated User

Seeing more code might be helpful. I'm not picturing what's happening. You're moving right_col to the left side of the window?

Are the right_col dimensions changing?

Are you AMD?

Are you checking to see if the dom is ready after stuff is moved around? The sync/async stuff can get screwy at times. Your map may have resized before the dom was ready (before your right_col moved).

What version of the API?

0 Kudos
JohnPreston
Deactivated User

Thanks Tyrone

I got it to behave the way I want. However when I add graphics to map and/or separate graphics layer they are not being redrawn correctly. They graphics are not in the correct position and are distorted. Do I need to update extent? Some other setting?

$('#printPane').hide();

$('#left_col').hide();

$('#right_col').css("float", "left");

$('#right_col').css("width", "700px");

$('#right_col').css("height", "500px");

$('#map').css("float", "left");

$('#map').css("width", "700px");

$('#map').css("height", "500px");

map.width = 700;

map.resize();

map.reposition();

0 Kudos
TyroneBiggums
Deactivated User

I'd probably need to see more code to replicate and see what you mean. And, you have map.width, the read-only property, set to 700. I'm not sure how much that helps you or how much it hinders you.

0 Kudos