question on bounds.extend and map.fitbounds

761 views
Skip to first unread message

Arjan

unread,
Aug 24, 2011, 4:48:54 AM8/24/11
to Google Maps JavaScript API v3
Hi!

On http://arjan64.home.xs4all.nl/test3.html you can find my new
attempt to draw 1 sector (for the moment still as a triangle) and then
update the boundaries of the map to include the full sector. I have
defined a variable to contain the boundaries and updated them with the
coordinates of the triangle. Still, when I do "fitBounds" on the map,
using these updated boundaries, nothing happens. To fix the map, I
have used these options:
disableDefaultUI: true,
disableDoubleClickZoom: true,
draggable: false,
scrollwheel: false,
zoomControl: false,
but releasing these settings did not make the fitBounds work. Can
someone suggest what's wrong?

Regards,

Arjan


Rossko

unread,
Aug 24, 2011, 5:21:50 AM8/24/11
to Google Maps JavaScript API v3
You have
bounds.extend(testSector2Coords);
where testSector2Coords is an array of LatLngs

Documentation says the parameter for extend should be a LatLng
http://code.google.com/apis/maps/documentation/javascript/reference.html#LatLngBounds

There is an extension to add a getBounds method to polygon
http://code.google.com/p/google-maps-extensions/source/browse/google.maps.Polygon.getBounds.js
so you could get the triangle bounds and use it directly in fitBounds

Arjan

unread,
Aug 24, 2011, 5:44:22 AM8/24/11
to Google Maps JavaScript API v3
> There is an extension to add a getBounds method to polygonhttp://code.google.com/p/google-maps-extensions/source/browse/google....
> so you could get the triangle bounds and use it directly in fitBounds

I tried

map.fitBounds(testSector2.getBounds);

where testSector2 is the polygon,
but that does not lead to any improvement.
What's wrong?

A.

Rossko

unread,
Aug 24, 2011, 6:43:28 AM8/24/11
to Google Maps JavaScript API v3
> I tried
>
> map.fitBounds(testSector2.getBounds);
>
> where testSector2 is the polygon,
> but that does not lead to any improvement.
> What's wrong?

I don't know, because that is not in the webpage that you are sharing
with us.

At a guess, you are wishing for the polygon getBounds() method but
have not actually implemented the necessary __extension__ to the API

Arjan

unread,
Aug 24, 2011, 8:22:35 AM8/24/11
to Google Maps JavaScript API v3
> I don't know, because that is not in the webpage that you are sharing
> with us.
>
> At a guess, you are wishing for the polygon getBounds() method but
> have not actually implemented the necessary __extension__ to the API


My new sample is here:

http://arjan64.home.xs4all.nl/test3c.html

I added a reference to file google.maps.Polygon.prototype.getBounds.js
in which I
have put the method as formulated on the sample page.
No polygon is shown, no rescaling is done...

Arjan

Arjan

unread,
Aug 24, 2011, 9:00:47 AM8/24/11
to Google Maps JavaScript API v3
It seems to work now. See:

http://arjan64.home.xs4all.nl/test6.html

Thanks!

A.

geoco...@gmail.com

unread,
Aug 24, 2011, 9:01:51 AM8/24/11
to Google Maps JavaScript API v3
Javascript errors are shown...

>
> Arjan

geoco...@gmail.com

unread,
Aug 24, 2011, 9:16:42 AM8/24/11
to Google Maps JavaScript API v3
On Aug 24, 1:48 am, Arjan <arjan.van.d...@rivm.nl> wrote:
> Hi!
>
> On
http://arjan64.home.xs4all.nl/test3.html
you can find my new
> attempt to draw 1 sector (for the moment still as a triangle) and then
> update the boundaries of the map to include the full sector. I have
> defined a variable to contain the boundaries and updated them with the
> coordinates of the triangle. Still, when I do "fitBounds" on the map,
> using these updated boundaries, nothing happens.

Why did you start a new thread?

You didn't do what I suggested here:
http://groups.google.com/group/google-maps-js-api-v3/browse_frm/thread/61d89dabeef5e48e#
> Create an empty LatLngBounds object, call the .extend method with
> every point you display on your map (vertices of the polygons as
> well), then call map.fitBounds with that LatLngBounds.

http://www.geocodezip.com/arjan64_home_xs4all_nl_test3a.html

-- Larry

Arjan

unread,
Aug 24, 2011, 9:30:06 AM8/24/11
to Google Maps JavaScript API v3
> Why did you start a new thread?

I have 3 threads now:
- one about static maps. Since I stepped over to JavaScript API v3
this thread is no longer applicable.
- one about clipping the boundaries of a map to include all elements
- one about an example that did not run.

I reckoned that my failure to run the downloaded example had a reason
that had nothing to do with fitting boundaries.
Therefore, I was afraid that if I would raise this topic in that
thread, people with possibly suggestions might not find it.


> You didn't do what I suggested here:http://groups.google.com/group/google-maps-js-api-v3/browse_frm/threa...
>
> > Create an empty LatLngBounds object, call the .extend method with
> > every point you display on your map (vertices of the polygons as
> > well), then call map.fitBounds with that LatLngBounds.
>
> http://www.geocodezip.com/arjan64_home_xs4all_nl_test3a.html


As you can see some messages up, I managed to make a rather decent,
self-scaling sector-plot!

Now that we are talking: is there a way to write text on the map?
E.g. add the numbers of the sectors and their radiuses?

Regards,


Arjan

geoco...@gmail.com

unread,
Aug 24, 2011, 9:41:11 AM8/24/11
to Google Maps JavaScript API v3
See my reply in your original thread...
(I have used InfoBox)

-- Larry

>
> Regards,
>
> Arjan

Arjan

unread,
Aug 24, 2011, 3:07:21 PM8/24/11
to Google Maps JavaScript API v3
> (I have used InfoBox)

Done! Good suggestion! Thanks!

See http://arjan64.home.xs4all.nl/test9.html for a sample.

--> question: how can I write a number to a string?

I would like to see the sector number in the label, plus the radius
[km] used.
Maybe even on 2 lines, so I also need a "newline" in my string.
Now, as a test, I pass a fixed string to the label: "Sector", which is
not so informative yet...

Regards,


Arjan

Arjan

unread,
Aug 24, 2011, 3:15:57 PM8/24/11
to Google Maps JavaScript API v3
> Maybe even on 2 lines, so I also need a "newline" in my string.

"Sector<br>radius" gives 2 lines.
But how to add the numerical values of iSector and Radius to the
string?

A.

geoco...@gmail.com

unread,
Aug 24, 2011, 3:39:38 PM8/24/11
to Google Maps JavaScript API v3
Javascript is not strongly typed.

"Sector="+iSector+"<br>radius="+Radius

Where iSector and Radius are your numbers should work. Try searching
the web for javascript tutorials on string handling and number
handling.

-- Larry

>
> A.

Arjan

unread,
Aug 24, 2011, 5:06:43 PM8/24/11
to Google Maps JavaScript API v3
> Javascript is not strongly typed.
> "Sector="+iSector+"<br>radius="+Radius


Larry, it works! You're a genius! Thanks!

A.

Arjan

unread,
Aug 25, 2011, 2:57:38 AM8/25/11
to Google Maps JavaScript API v3
I updated the above test:
http://arjan64.home.xs4all.nl/test9.html
to include the sector numbers and radiuses.

Now I an wondering how to add some interface where you can specify:
-lon/lat of the central location (default e.g. the location in
test9.html)
-number of sectors in a full circle (default 8)
-for each sector 3 radiuses (all default 0)
This interface would make test9.html into an application that I can
pass over to my colleagues to use in real life. Now it is just a test.
This is probably more an HTML-question than a Google Maps JavaScript
API v3-question, but then the values have to be passed over to the
JavaScript script to affect the map.

Would anyone know a simple example?

Regards,

Arjan

Arjan

unread,
Aug 25, 2011, 3:29:08 AM8/25/11
to Google Maps JavaScript API v3
ps. How can I activate the nice little black ruler at the bottom,
showing the scale of the map?

A.

Arjan

unread,
Aug 25, 2011, 4:07:29 AM8/25/11
to Google Maps JavaScript API v3
Hi (again)!

In http://arjan64.home.xs4all.nl/test10.html you can see my latest
experiment to add a distance measuring device (which does not say that
I am not looking for the nice little black, fixed ruler at the
bottom! ;-)) ). It works well, but I don't like to have the button in
a separate white line on top of the map.

--> Is there a way to put that button somewhere on the map itself?
--> And how do I remove that thing in the top-left corner that allows
you to shift the map? The map is fine as it is, no need to allow for
tampering with it!

Arjan

Rossko

unread,
Aug 25, 2011, 6:35:55 AM8/25/11
to Google Maps JavaScript API v3
Have you tried any of the documentation?

> (which does not say that
> I am not looking for the nice little black, fixed ruler at the
> bottom! ;-)) )

Scale control
http://code.google.com/apis/maps/documentation/javascript/controls.html

> It works well, but I don't like to have the button in
> a separate white line on top of the map.
> --> Is there a way to put that button somewhere on the map itself?

You could implement it on the map as a custom control
http://code.google.com/apis/maps/documentation/javascript/controls.html

> --> And how do I remove that thing in the top-left corner that allows
> you to shift the map?

You could disbale the default controls
http://code.google.com/apis/maps/documentation/javascript/controls.html

Arjan

unread,
Aug 25, 2011, 6:44:18 AM8/25/11
to Google Maps JavaScript API v3
In

http://arjan64.home.xs4all.nl/test11.html

I added 2 entries for entering lon and lat of the central location,
plus a button that should
update the map (still, like the other button, in a separate part of
the screen and not ON the map,
but that's a different topic). I must have goofed up completely, since
pressing that button makes
the page complain and nothing useful happens.

How can I make it such that the initial values of the entries for Lon
and Lat
match the lon and lat of the central location as known by the
JavaScript part?
And how can I pass modified values to my sector plot when I press that
button?

I have placed the definition and initialization of the central
location
outside the initialization routine. I hoped that this would pave the
way
for using the initialization routine as update-routine for the plot:
update the lon and lat of the centre and re-plot the map.
It didn't work.

Who has a suggestion for improvement?

Regards,

Arjan

Arjan

unread,
Aug 25, 2011, 6:57:29 AM8/25/11
to Google Maps JavaScript API v3
> Have you tried any of the documentation?

Of course! Otherwise I wouldn't be where I am right now! For a full
novice in both HTML and in JavaScript (I started last tuesday), I feel
pretty impressed by what I have already achieved in 2 days. With some
help from the regulars on this forum, that's true. But I hope my
requests don't seem to point into passiveness on my side! I do my
best! And I appreciate your help!


> Scale controlhttp://code.google.com/apis/maps/documentation/javascript/controls.html

Found! Thanks!
I assumed "Scale" meant "Zoom", so I had missed this one!


> > --> And how do I remove that thing in the top-left corner that allows
> > you to shift the map?
>
> You could disbale the default controlshttp://code.google.com/apis/maps/documentation/javascript/controls.html

This works too! great!


> > It works well, but I don't like to have the button in
> > a separate white line on top of the map.
> > --> Is there a way to put that button somewhere on the map itself?
>
> You could implement it on the map as a custom controlhttp://code.google.com/apis/maps/documentation/javascript/controls.html

I'll have a peek into this later today!
Thanks for pointing me at the right documentation!

Regards,


Arjan
Reply all
Reply to author
Forward
0 new messages