Loading kml files and google map asset


(Eric) #1

Can I use kml file with google map asset?


Google asset is great, but I need to add few things to intialisation of the map, to pull data from KML file, how do I do it without breaking the map?

Example[codebox] <script src="http://www.google.com/jsapi?key=<<INSERT KEY>>"></script>

<script type="text/javascript">

google.load("maps", "2");

</script>

<script type="text/javascript">

var map;

var geoXml;

var toggleState = 1;



function loadMap() {

if (GBrowserIsCompatible()) {

geoXml = new GGeoXml("http://static.parracity.nsw.gov.au/insertfilenamehere.kml");

map = new GMap2(document.getElementById("content"));

map.setCenter(new GLatLng(-33.81690978367445,151.0049021244049), 15);

map.addControl(new GLargeMapControl());

map.addControl(new GLargeMapControl());

map.addOverlay(geoXml);

}

}



function toggleMyKml() {

if (toggleState == 1) {

map.removeOverlay(geoXml);

toggleState = 0;

} else {

map.addOverlay(geoXml);

toggleState = 1;

}

}

google.setOnLoadCallback(loadMap);

</script>[/codebox]


(Huan Nguyen) #2

You can certainly use KML file with the google map asset. There are 3 things you have to do

  1. Add your code to the "Map Initialization" Attribute in the detail screen of the Google Map asset. Please use the code provided here as the code you provided has overlap of variable names for the map.


    KML (there is a space added by the forum automatically between "java" and "script" in this line, you would have to change it back to "javascript")
    
    


( These 2 steps need to be done if you are only listing locations in the KML file, otherwise you can ignore them)
2. Select the asset type to list, can be any asset type since you are only concern about the KML. Choose a listing rootnode that does not contain any of those asset type.

3. Make sure your Page Contents (No Results) bodycopy of the map asset has the same content as the Page Contents bodycopy.
i.e. "%google_map% %asset_listing%".

And that's it. Let me know how it goes, I have tried this.

(Eric) #3

Thank you very much!!! It worked!!! very exiting.


The kml file has an outline of waste cleanup area so residents can do a search on they address and a pin falls on they location within outline. How can I make it better? You see the pin(pop-up) shows the searched address details, kml file has the cleanup dates for every zone, if you click on a zone produced by kml file overlay you see a pop-up with dates, but it is not obvious that you have to click on it. Any way to make both pop-ups come up at once one with the location and one from the zone it fell to?



Am I pushing my luck?



I can see it would be difficult as the locations are searched through google maps have no correlation to the zones in a file other then visual.


(Huan Nguyen) #4

This is a tough one. I reckon there is hardly a way to make them popup at the same time, and you would have to modify the KML file and put in some XML. I looked at the KML specification (http://code.google.com/apis/kml/documentation/) and I couldn't find anything. Have a look there and try your luck.
Do you have a lot of these locations? You can probably put a text in the searched address popup to tell people to click on the outline as an alternative, but it is no way equivalent to the double popup solution =(. There is not much I can help you with as the map asset have no control over the locations plotted by the KML file.


(Eric) #5

Thanks I thought it would be difficult, but a good idea to put it in to a pop-up. Even as it is a vast improvement on we had before I know most of council clients will be interested in this, as most have GIS capabilities.


(Huan Nguyen) #6

Glad to be of help =).


(Eric) #7

Hello again, another question.


When you do a search on a google maps (website) for an address the result changes zoom level (zoom in on a pin)



How can I replicate this functionality in matrix? The result of the search return arguments I am sure but how do i add to them in matrix?

example here: http://static.parracity.nsw.gov.au/schedule_cleanup.html



I am not sure if I am being clear.


(Huan Nguyen) #8

Originally I was implementing this feature which let you zoom in the set focus on the search point, but then i thought it was annoying, and different people would expect different zoom level / or simply dont want to zoom in.


I assume you already know how to implement searching for an address with the Google Map asset?

Instead of using the %google_map_address_finder% keyword, you can put this HTML in a RAW HTML div under the Page Contents bodycopy of the asset map. (I am also assuming that you list other locations besides the KML locations, otherwise you should use the Page Contents (No Results) bodycopy)


    

<a href="java script:findAndPop();" style="border:0px;">FIND</a>
</div></pre><br />

If this still not satisfy you / somehow you experience problem (I tried and it works just fine on my map), then let me know, I'l take you a bit further =).

(Eric) #9

I see, I will try it, kml file only has outlines not specific locations, I am trying to add labels to the outlines so people have genreal idea which ZONE they are in before clicking.


Thanks for your help I will try it next week have a good weekend


(Jefferyca) #10

[quote]
Originally I was implementing this feature which let you zoom in the set focus on the search point, but then i thought it was annoying, and different people would expect different zoom level / or simply dont want to zoom in.



I assume you already know how to implement searching for an address with the Google Map asset?

Instead of using the %google_map_address_finder% keyword, you can put this HTML in a RAW HTML div under the Page Contents bodycopy of the asset map. (I am also assuming that you list other locations besides the KML locations, otherwise you should use the Page Contents (No Results) bodycopy)


    

<a href="java script:findAndPop();" style="border:0px;">FIND</a>
</div></pre><br />

If this still not satisfy you / somehow you experience problem (I tried and it works just fine on my map), then let me know, I'l take you a bit further =).
[/quote]

G'Day Huan,

I have used your code above (with modification after looking at the source - var marker = findLocationFromAddress("80 Smith St, Woden, ACT", "place name<BR/>Ph: <BR/><a target='_blank' href='http://www.example.com'>www.example.com</a><br/>","","","1"); ).

When the map with the location loads the pop up shows only the address. When I click on the marker I get the popup with the extra text. Is there anyway to make it load the extra text initially?.

Thanks.