0

I have a written up HTML file using the Google Maps API v3.

All I want to do is color a couple of countries, for example, color in China and Canada to red. What is a simple solution (that doesn't involve Polygons and thousands of coordinates) to color in countries?

After browsing previous StackOverFlow questions, there seemed to be three common solutions. However these 3 solutions do not seem appropriate for my situation.

  1. Charts API -I don't really understand if Charts API is a good solution for me because I have already have a file using Google Maps API. Unless Charts can be applied over my map, or synchronize with the map, this does not seem to be a valid solution.

  2. Styling (With Styling Wizard) -This wizard (as far as I know) deals with the style of general characteristics, like road, water, population, etc. Unless someone can show me how to assign a specific country a color, I do not see how this can work.

  3. Polygons -I saw the example of the Bermuta triangle and other people have suggested to get the coordinates of the perimeter of a country and create a polygon. This may work except I may need a thousands of coordinates in order to fully outline China. Perhaps there is a more simple method in which I can color in a country?

krikara
  • 2,395
  • 10
  • 37
  • 71
  • I've done this before using technique #3. I used a polygon optimizer program (written in C) to reduce 1000+ coordinates down to ~50 coordinates. The "optimized" polygon will have a jagged appearance (of course). – Salman A Jun 18 '12 at 06:32

2 Answers2

2

Use either FusionTablesLayer or KmlLayer. Both take kml formated geographical data and render it on tiles, yielding better performance with complex or large numbers of polygons.

The Natural Earth data set is available in Fusion Tables, and contains most countries.

geocodezip
  • 158,664
  • 13
  • 220
  • 245
  • Okay, from what I understand, Fusion tables are more complex polygons. The Natural Earth Data set should have the data for the country in polygon terms. When I click that link of the natural earth data in the the google fusion tables, I am not sure how to interpret or use this data. The countries file comes in a csv file. It is also very hard to learn about the fusion tables because all the examples for the documentation are blocked in China – krikara Jun 19 '12 at 09:41
  • Here is an [example showing the countries](http://www.geocodezip.com/v3_FusionTablesLayer_worldmap_linkto.html), here is my "[country browser](http://www.geocodezip.com/geoxml3_test/v3_FusionTables_CountryBrowser.html)", and [here is it showing China](http://www.geocodezip.com/geoxml3_test/v3_FusionTables_CountryBrowser.html?country=China). – geocodezip Jun 19 '12 at 12:52
  • Okay, here is where I am stuck. I have two files, one file that is able to color in countries and one file that has markers with labels. To get marker with labels, another user helped me out and gave me a regex file for the markers. Now, I have noticed that if I have the regex line present, the markers are displayed, but the country color is not. If I comment out that line, the markers are not displayed, but the country color is. How should I solve this problem? I can post any necessary code if needed. – krikara Jun 20 '12 at 05:43
  • Sorry, here is a correction. I am not actually able to combine the files and when there is a regex line present, the country color does not work. – krikara Jun 20 '12 at 05:54
  • Okay posted two links in my original post. – krikara Jun 20 '12 at 06:38
  • Oh I finally got it to work. Apparently, I need to create the markers at the beginning of my initialize statement. Kind of weird... but it works now. Thanks a bunch for all your help. Well, I do have one last question. Is it possible to assign a different color for a diff country? All the country colors are done with Fusion tables, and I don't really know much about it except to use it and get my country in red. – krikara Jun 20 '12 at 08:33
  • Yes, you can dynamically style FusionTablesLayers using javascript. See – geocodezip Jun 20 '12 at 12:34
  • While on the topic of fusion tables, is it possible to create a table on the map at a specific zoom level? I've been browsing examples and they are all static (unanchored) tables regardless of zoom level. For my purpose, I would like to make a table at a specific location in the ocean only viewable at a specific zoom. – krikara Jun 21 '12 at 02:07
  • Using the google maps API v3 you can only show the FusionTablesLayer at a particular zoom (I'm not sure what you mean by "create a table on the map at a specific zoom level"). I never saw the links that you said you posted so I don't know what you are trying to do or what your map code looks like. – geocodezip Jun 21 '12 at 02:53
  • My map used markers with labels placed specific cities, but what happened was that sometimes cities are too close together and the markers overlap each other. Therefore I want to create a table like this https://developers.google.com/fusiontables/docs/samples/legend. But this table is constantly at the bottom right of the map and displayed on all zoom levels. I want my table to be anchored in to a location as well as only visible on certain zooms. Is this possible? – krikara Jun 21 '12 at 03:21
  • And I don't exactly understand why, but I can't seem to create my own tables. Conversely, the code pasted at the bottom of that link also does not work for me. – krikara Jun 21 '12 at 03:32
  • Yes. Look at 1: the zoom_changed event, 2: [InfoBox](http://google-maps-utility-library-v3.googlecode.com/svn/trunk/infobox/docs/reference.html), here is [an example](http://www.geocodezip.com/ParkerPalmSprings.html) where polygons are annotated once the zoom is close enough. – geocodezip Jun 21 '12 at 03:34
  • I think I will just ask a new question for this seeing as this post is getting excessively long. On a side note, I am trying to create a table or a list of cities with their associate numbers, and not wanting to use infobox. – krikara Jun 21 '12 at 03:37
0

This might work for you if coordinates generated automatically in different resolutions depending on your requirements. all you need to do is to load an appropriate GeoJSON onto your map. See here for the complete answer which is done just by adding a couple of line of codes.

enter image description here

Rman
  • 458
  • 4
  • 7