Polygon and tile?

63 views
Skip to first unread message

john

unread,
Oct 18, 2010, 9:14:52 AM10/18/10
to Google Maps JavaScript API v3
I have polygons that has huge number of points. One of the polygon was
over 300,000 points originally. It is still huge after we smoothed it.

In v2, I uses FromEncoded(). The performance is bad but at least it
shows on the map. I understand that the polygon drawing is improved in
v3. But with some many points, I don't feel it will do too much.

I think the best solution is to use tiles. Even there are lots of
tiles at deep levels. But most will be blank. Following is what's in
my mind.

Create database table with key on (zoom, x, y) and an image column
store the images (or a reference to a image file).

for each tile in my country (zoom, x, y) // how to get the coords?
{
for each (polygon that intersects the tile)
draw the polygon on the tile.

save the tile and remember it is database.
}

When request for (zoom, x, y), I simply search the database, return
the image if finds one.

The idea is simple and I believe it can be done. My questions are:

Is there any service/tool that can do what I described. I see tile
cutting tools but all take an image as input which will lost details
when doom in.Also, I don't want all those blank images.

Chad Killingsworth

unread,
Oct 18, 2010, 9:50:54 AM10/18/10
to Google Maps JavaScript API v3
You should use either Fusion Tables or KML Layers. They are both built
to handle that type of work for you.

Chad Killingsworth

Martin

unread,
Oct 18, 2010, 10:09:22 AM10/18/10
to Google Maps JavaScript API v3

john

unread,
Oct 18, 2010, 1:28:54 PM10/18/10
to Google Maps JavaScript API v3
I don't see KML layers will offer much performance improvement. But I
will give it a try.

I know how the coord system works. But that's the first step to create
tiles. That why I am asking if there existing tools or service that I
can use (instead build my own).




On Oct 18, 9:09 am, Martin <warwo...@gmail.com> wrote:
> http://code.google.com/apis/maps/documentation/javascript/maptypes.ht...

Chad Killingsworth

unread,
Oct 18, 2010, 3:39:43 PM10/18/10
to Google Maps JavaScript API v3
Kml Layers will give you a HUGE improvement. Google's servers actually
process your kml files and send the client a single set of image tiles
- exactly what you were after. Let them do the heavy lifting.

Chad Killingsworth

john

unread,
Oct 19, 2010, 1:39:46 AM10/19/10
to Google Maps JavaScript API v3
Chad,

I can't even get the kml file working properly.

http://209.35.190.130/kmltest/sg.html

It only show one boundary while I have many polygons in the file.
Cannot preserve the viewport.
Cannot supress the infowindow.

Can you take a look to see what is wrong?

Thanks.

John

On Oct 18, 2:39 pm, Chad Killingsworth

geoco...@gmail.com

unread,
Oct 19, 2010, 2:53:43 AM10/19/10
to Google Maps JavaScript API v3
On Oct 18, 10:39 pm, john <john.c...@aafa-inc.com> wrote:
> Chad,
>
> I can't even get the kml file working properly.
>
> http://209.35.190.130/kmltest/sg.html
>
> It only show one boundary while I have many polygons in the file.

Google Maps doesn't like your kml (I'm not sure why, but it must be
expecting more complex kml, yours is probably missing something that
it expects).

geoxml3 seems to show all the pieces:
http://www.geocodezip.com/geoxml3_test/kmltest_SG_sidebar.html
(for whatever that is worth, there doesn't seem to be any data
associated with the polygons)

-- Larry

Chad Killingsworth

unread,
Oct 19, 2010, 8:24:01 AM10/19/10
to Google Maps JavaScript API v3
If you have more than one placemark, your placemark nodes need to be
wrapped in a <Document> node. You can always test your kml by loading
it in Google Earth and at maps.google.com (put the kml url in the
search bar).

Chad Killingsworth

On Oct 19, 1:53 am, "geocode...@gmail.com" <geocode...@gmail.com>
wrote:

geoco...@gmail.com

unread,
Oct 19, 2010, 8:30:54 AM10/19/10
to Google Maps JavaScript API v3
On Oct 19, 5:24 am, Chad Killingsworth
<chadkillingswo...@missouristate.edu> wrote:
> If you have more than one placemark, your placemark nodes need to
> be wrapped in a <Document> node.

Where is that defined/stated?

> You can always test your kml by
> loading it in Google Earth and at maps.google.com (put the kml url
> in the search bar).

maps.google.com doesn't complain:
http://maps.google.com/maps?hl=en&q=http:%2F%2F209.35.190.130%2Fkmltest%2FSG.kml&client=gmail&ie=UTF8&t=h&z=13
but only displays one polygon. I didn't try google earth

The kml validator only complains about the lack of an id:
http://www.feedvalidator.org/check.cgi?url=http%3A%2F%2F209.35.190.130%2Fkmltest%2FSG.kml

-- Larry

Chad Killingsworth

unread,
Oct 19, 2010, 10:16:07 AM10/19/10
to Google Maps JavaScript API v3
> <chadkillingswo...@missouristate.edu> wrote:
> > If you have more than one placemark, your placemark nodes need to
> > be wrapped in a <Document> node.
>
> Where is that defined/stated?

http://code.google.com/apis/kml/documentation/kmlreference.html#kml
A basic <kml> element contains 0 or 1 Feature and 0 or 1
NetworkLinkControl:

> > You can always test your kml by
> > loading it in Google Earth and at maps.google.com (put the kml url
> > in the search bar).
>
> maps.google.com doesn't complain:http://maps.google.com/maps?hl=en&q=http:%2F%2F209.35.190.130%2Fkmlte...
> but only displays one polygon.  I didn't try google earth

Correct (Google Earth doesn't complain either but only displays 1
poly) - but in all instances, it's not what he wants. Therefore the
problem lies in the KML and not in the map or javascript.

Chad Killingsworth

john

unread,
Oct 19, 2010, 3:53:50 PM10/19/10
to Google Maps JavaScript API v3
Chad, Larry,

Added <Document> tag. it worked.

I then went on created one for Australia. The file size is 19M and the
boundaries did not show up.

BUT, I then created one for Tasmania (the one part that has the most
points in AU). It shows HUGE (thanks Chad) performance improvement
over my FromEncoded() method.

So, even with the size limitation of the kml, I will use this approach
(with clustering at country zoom level).

Thanks a lot for your insight and help.

John

On Oct 19, 9:16 am, Chad Killingsworth

john

unread,
Oct 19, 2010, 3:55:29 PM10/19/10
to Google Maps JavaScript API v3
Tasmania http://209.35.190.130/kmltest/au.html


On Oct 19, 9:16 am, Chad Killingsworth

Chad Killingsworth

unread,
Oct 19, 2010, 4:41:20 PM10/19/10
to Google Maps JavaScript API v3
You can use a KMZ file (compressed KML) to be able to pass more data.

Chad Killingsworth

john

unread,
Oct 23, 2010, 1:19:05 PM10/23/10
to Google Maps JavaScript API v3
Now I have more question about KML.

Take the example of Tasmania. How can show one of the sub-region in a
different (line) color.

A sub-region may contain multiple polygons (like those islands).
I also like to change the color dynamically.

TIA.

John






On Oct 19, 3:41 pm, Chad Killingsworth

Rossko

unread,
Oct 23, 2010, 3:03:42 PM10/23/10
to Google Maps JavaScript API v3
> Now I have more question about KML.

http://code.google.com/apis/kml/documentation/kml_tut.html
http://groups.google.com/group/kml-support?lnk=srg

> Take the example of Tasmania. How can show one of the sub-region  in a
> different (line) color.

http://code.google.com/apis/kml/documentation/kmlreference.html#linestyle

> A sub-region may contain multiple polygons (like those islands).

http://code.google.com/apis/kml/documentation/kmlreference.html#multigeometry

> I also like to change the color dynamically.

In response to what, or just at random?

geoco...@gmail.com

unread,
Oct 23, 2010, 4:06:10 PM10/23/10
to Google Maps JavaScript API v3
On Oct 23, 12:03 pm, Rossko <ros...@culzean.clara.co.uk> wrote:
> > Now I have more question about KML.
>
> http://code.google.com/apis/kml/documentation/kml_tut.htmlhttp://groups.google.com/group/kml-support?lnk=srg
>
> > Take the example of Tasmania. How can show one of the sub-region  in a
> > different (line) color.
>
> http://code.google.com/apis/kml/documentation/kmlreference.html#lines...
>
> > A sub-region may contain multiple polygons (like those islands).
>
> http://code.google.com/apis/kml/documentation/kmlreference.html#multi...

You also need to worry about what parts of KML kmlLayer supports:
http://code.google.com/apis/kml/documentation/mapsSupport.html

-- Larry

john

unread,
Oct 23, 2010, 6:10:16 PM10/23/10
to Google Maps JavaScript API v3
OK, <MultiGeometry> did the trick on put multiple polygons in one
<Placemark> (mapsSupport.html did not list MultiGeometry and I
worried)
and I can give a name to the Placemark.

Now I want to change the color to red of one Placemark based on the
name of the Placemark. How can I do that?

On Oct 23, 3:06 pm, "geocode...@gmail.com" <geocode...@gmail.com>
wrote:
> On Oct 23, 12:03 pm, Rossko <ros...@culzean.clara.co.uk> wrote:
>
> > > Now I have more question about KML.
>
> >http://code.google.com/apis/kml/documentation/kml_tut.htmlhttp://grou...

Chad Killingsworth

unread,
Oct 24, 2010, 8:17:06 AM10/24/10
to Google Maps JavaScript API v3
<MultiGeometry> is supported - I use it.

Each placemark can contain either a <style> node or a <styleUrl> which
references a <Style id="XXX"> node that is a direct descendant of the
<Document> node. The <Style> node contains definitions for icons. For
a basic example, take a look at http://search.missouristate.edu/map/kml/?layers=shuttle&routes=red

Chad Killingsworth

geoco...@gmail.com

unread,
Oct 24, 2010, 11:06:39 AM10/24/10
to Google Maps JavaScript API v3
On Oct 24, 5:17 am, Chad Killingsworth
<chadkillingswo...@missouristate.edu> wrote:
> <MultiGeometry> is supported - I use it.

Perhaps it should be listed on this page:
http://code.google.com/apis/kml/documentation/kmlelementsinmaps.html

>
> Each placemark can contain either a <style> node or a <styleUrl>
> which references a <Style id="XXX"> node that is a direct
> descendant of the <Document> node. The <Style> node contains
> definitions for icons.

It should contain the definitions for the polygons as well.
I believe the StyleMap element supports changing styles, but I believe
that is also listed as not supported (or at least partially
supported).

-- Larry

john

unread,
Oct 24, 2010, 11:33:38 AM10/24/10
to Google Maps JavaScript API v3
Take your shuttle example. Paste it to the search in google maps. You
will see a list check boxes allow you to check off the items on the
map. What I really wanted is to have a way to change the red line to
blue (instead of simple check it off).



On Oct 24, 7:17 am, Chad Killingsworth
<chadkillingswo...@missouristate.edu> wrote:
> <MultiGeometry> is supported - I use it.
>
> Each placemark can contain either a <style> node or a <styleUrl> which
> references a <Style id="XXX"> node that is a direct descendant of the
> <Document> node. The <Style> node contains definitions for icons. For
> a basic example, take a look athttp://search.missouristate.edu/map/kml/?layers=shuttle&routes=red

geoco...@gmail.com

unread,
Oct 24, 2010, 12:09:44 PM10/24/10
to Google Maps JavaScript API v3
On Oct 24, 8:33 am, john <john.c...@aafa-inc.com> wrote:
> Take your shuttle example. Paste it to the search in google
> maps. You will see a list check boxes allow you to check off the
> items on the map. What I really wanted is to have a way to
> change the red line to blue (instead of simple check it off).

You need to have access to the underlying polyline to do that. I
don't think kmlLayers gives you that access. Maybe Chad knows how or
if the API team is going to do that. You could probably file an
enhancement request:
http://code.google.com/p/gmaps-api-issues/issues/list?can=2&q=apitype:Javascript3

This page creates a Polyline using that KML and allows changing its
color:
http://www.geocodezip.com/geoxml3_test/v3_geoxml3_MSUCampusMap.html

(probably doesn't meet your performance needs though)

-- Larry

Chad Killingsworth

unread,
Oct 24, 2010, 2:44:06 PM10/24/10
to Google Maps JavaScript API v3
You're right in that the API doesn't give you direct access to that.
You can however manipulate the kml and remove the old layer and add a
new one. Your users will have to download a new set of image tiles
when you do this.

Chad Killingsworth

On Oct 24, 11:09 am, "geocode...@gmail.com" <geocode...@gmail.com>
wrote:
> On Oct 24, 8:33 am, john <john.c...@aafa-inc.com> wrote:
>
> > Take your shuttle example. Paste it to the search in google
> > maps. You will see a list check boxes allow you to check off the
> > items on the map. What I really wanted is to have a way to
> > change the red line to blue (instead of simple check it off).
>
> You need to have access to the underlying polyline to do that.  I
> don't think kmlLayers gives you that access.  Maybe Chad knows how or
> if the API team is going to do that.  You could probably file an
> enhancement request:http://code.google.com/p/gmaps-api-issues/issues/list?can=2&q=apitype...

Rossko

unread,
Oct 24, 2010, 4:04:10 PM10/24/10
to Google Maps JavaScript API v3
I wonder if perhaps a seperate page is really needed ; that page seems
to me to be intended to describe the KML capabilities of
maps.google.com And, presumably, the old API v2 GGeoXml since it
appears to use the same parser.

KmlLayer seems to be a different fish, and may always be so?

john

unread,
Oct 24, 2010, 11:40:55 PM10/24/10
to Google Maps JavaScript API v3
I will try the following.

Create a new set of KML for each sub-region (with red lines). I then
lay one of the sub-regions on top of the whole region kml/polygons.
I just don't know how can I be sure it is ON TOP.

john

unread,
Oct 25, 2010, 12:22:37 AM10/25/10
to Google Maps JavaScript API v3
It worked.

http://209.35.190.130/kmltest/sg80.html

One trick part is that I have to use the same KmlLayerOptions object.

Chad Killingsworth

unread,
Oct 25, 2010, 10:09:16 AM10/25/10
to Google Maps JavaScript API v3
> KmlLayer seems to be a different fish, and may always be so?

I believe this is the case. A separate page would be best.

Chad Killingsworth

john

unread,
Oct 25, 2010, 1:03:20 PM10/25/10
to Google Maps JavaScript API v3
Well, it stopped working when I get up in the morning. I am creating a
separate thread.
Reply all
Reply to author
Forward
0 new messages