Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Heat map capability #111

Open
rbruhn opened this issue Jan 18, 2017 · 2 comments
Open

Heat map capability #111

rbruhn opened this issue Jan 18, 2017 · 2 comments

Comments

@rbruhn
Copy link

rbruhn commented Jan 18, 2017

Can this package be used with heat maps?
https://developers.google.com/maps/documentation/javascript/examples/layer-heatmap

@bradcornford
Copy link
Owner

Hi there,

Yes this is certainly possible, try something along the lines of:

Controller.php:

    public function index()
    {
        Mapper::map(37.775, -122.434, ['zoom' => 13, 'marker' => true, 'type' => MapperBase::TYPE_SATELLITE, 'eventBeforeLoad' => 'initiliseHeatmap(map_0);']);

        return view('view');
    }

view.blade.php:

<script type="text/javascript">

                    function initiliseHeatmap(map)
                    {
                        heatmap = new google.maps.visualization.HeatmapLayer({
                            data: [
                                new google.maps.LatLng(37.782551, -122.445368),
                                new google.maps.LatLng(37.782745, -122.444586),
                                new google.maps.LatLng(37.782842, -122.443688),
                                new google.maps.LatLng(37.782919, -122.442815),
                                new google.maps.LatLng(37.782992, -122.442112),
                                new google.maps.LatLng(37.783100, -122.441461),
                                new google.maps.LatLng(37.783206, -122.440829),
                                new google.maps.LatLng(37.783273, -122.440324),
                                new google.maps.LatLng(37.783316, -122.440023),
                                new google.maps.LatLng(37.783357, -122.439794),
                                new google.maps.LatLng(37.783371, -122.439687),
                                new google.maps.LatLng(37.783368, -122.439666),
                                new google.maps.LatLng(37.783383, -122.439594),
                                new google.maps.LatLng(37.783508, -122.439525),
                                new google.maps.LatLng(37.783842, -122.439591),
                                new google.maps.LatLng(37.784147, -122.439668),
                                new google.maps.LatLng(37.784206, -122.439686),
                                new google.maps.LatLng(37.784386, -122.439790),
                                new google.maps.LatLng(37.784701, -122.439902)
                            ],
                            map: map
                        });
                    }

                </script>

javascript.blade.php:

@if (!$view->shared('javascript', false))

    @if ($view->share('javascript', true)) @endif

    @if ($options['async'])

        <script async defer type="text/javascript" src="//maps.googleapis.com/maps/api/js?v={!! $options['version'] !!}&region={!! $options['region'] !!}&language={!! $options['language'] !!}&key={!! $options['key'] !!}&signed_in={!! $options['user'] ? 'true' : 'false' !!}&libraries=places,visualization&callback=initialize_method"></script>

    @else

        <script type="text/javascript" src="//maps.googleapis.com/maps/api/js?v={!! $options['version'] !!}&region={!! $options['region'] !!}&language={!! $options['language'] !!}&key={!! $options['key'] !!}&signed_in={!! $options['user'] ? 'true' : 'false' !!}&libraries=places,visualization"></script>

    @endif

    @if ($options['cluster'])

        <script type="text/javascript" src="//googlemaps.github.io/js-marker-clusterer/src/markerclusterer.js"></script>

    @endif

    @if ($options['async'])

        <script type="text/javascript">

            var initialize_items = [];

            function initialize_method() {
                initialize_items.forEach(function(item) {
                    item.method();
                });
            }

        </script>

    @endif

@endif

@Hmerman6006
Copy link

Hmerman6006 commented Aug 14, 2022

Using your suggested solution leads to google.maps.visualization is undefined console error. If I add the visualization library I receive an error that multiple instances of google.maps will lead to problems. How do I extend the Mapper object to include google.maps.visualization library?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants