egeloen / IvoryGoogleMapBundle

Google Map API v3 integration for your Symfony2 project.
https://github.com/egeloen/ivory-google-map
MIT License
217 stars 152 forks source link

Integrate KML import #17

Closed cbeyer closed 12 years ago

cbeyer commented 12 years ago

Hello,

Nice Bundle, thanks !

I need to use KML files in my Google Maps. http://code.google.com/intl/fr-FR/apis/maps/documentation/javascript/layers.html#KMLLayers

Could you adapt the bundle to implement that ?

egeloen commented 12 years ago

Thanks ! Unfortunately, I dont' have any time actually, i'm totally busy but I'm ok to add KML support to the bundle.

I'll explain you what I would have done if I had time. So, If you want, you can do it and i will merge it :)

IMO, after looking the google map doc, we need to create a KMLLayer class which extends AbstractJavascriptVariableAsset and will be stored under the Model/Layers directory. This class will describe the kml layer options according to KMLLayer and KMLLayerOptions.

To link the kml layer to the map, we need to add a kmlLayer property to the Map and this getter & setter. Additionnaly, we need to add a convenient method called hasKMLLayer() to check if the map has a kml layer (This method will be usefull in the helper). If the kmlLayer property is null, there is no kml layer otherwise there is.

After that, we need to create a KMLLayerHelper class which will render the javascript. This class will be stored under the Templating/Helper/Layers dicretory. I think, it will just have one method (render(KMLLayer $layer) which will return the KML layer javascript.

Now, we have our business and templating classes, we need to create the associated symfony2 services to allow users to request a kml layer in their controllers. The KMLLayer service can be named ivory_google_map.kml_layer and the KMLLayerHelper can be named ivory_google_map.helper.kml_layer. The KMLLayerHelper service is not public, it is created to be injected into the ivory_google_map.helper.map which renders a map and so will render the kml layer. So , to finish, we need to inject this service, update the MapHelper constructor to accept the KMLLayerHelper injected, create a new method called renderKMLLayer(Map $map) where we will use the KMLLayerHelper if the map has a kml layer.

If you have some questions, I'm here :)

cbeyer commented 12 years ago

Thanks for the explanations. Unfortunately, I'm busy too, I have never use Github for pull request, and I don't think I could make what required is... Here is my JS code. I will continue add this "at hand" until this bundle integrate this.

var kmlLayerOptions = {
preserveViewport: true // for example
}
var ctaLayer = new google.maps.KmlLayer('http://myUrl.kml', kmlLayerOptions);
ctaLayer.setMap(map);
wodor commented 12 years ago

I'll need this also in near future. I've looked around to implement it, and have some questions :

I had limited time today so It's just a beginning.

https://github.com/wodor/IvoryGoogleMapBundle/tree/kmlSupport

btw i had problem with :

/home/wodor/wrk/www/motowypady/vendor/bundles/Ivory/GoogleMapBundle/Model/Overlays/Polygon.php on line 14

after

it's fixed

another problem maybe it's my own , but it seems that phpunit run in bundle's root doesn't excludes vendor dir (like it's specified in phpunit.xml.dist) i can only do i.e.

egeloen commented 12 years ago

This issue can be closed :)

cbeyer commented 12 years ago

Great, thanks ! I will test this.

cbeyer commented 12 years ago

And it works great :)

egeloen commented 12 years ago

Thanks for feedbacks !