2amigos / yii2-leaflet-extension

Yii 2 Extension library to display interactive maps with Leaflet .
http://yiiwheels.com
Other
30 stars 25 forks source link

Mapquest API key #26

Open joetwostep opened 8 years ago

joetwostep commented 8 years ago

This is more a question of how to use the extension to access Mapquest rather than an issue with the extension itself. I developed a site using the Mapquest tileset and it has worked well for me using this sample code given in the readme file:

// The Tile Layer (very important) $tileLayer = new TileLayer([ 'urlTemplate' => 'http://otile{s}.mqcdn.com/tiles/1.0.0/map/{z}/{x}/{y}.jpeg', 'clientOptions' => [ 'attribution' => 'Tiles Courtesy of MapQuest ' . ', ' . 'Map data © OpenStreetMap contributors, CC-BY-SA', 'subdomains' => '1234' ] ]);

My question is don't I need a Mapquest API key? When I read Mapquest's terms and conditions it says I am limited to 15000 requests per month, my site is currently in development but I plan to release it live soon and am wondering if I hit that limit will my IP be banned from any more requests? I created an API key which should allow me to track my transactions but cannot figure out how to pass the key in using the code I have. Should I pass it as an extra option under "clientOptions"? I have googled and every source I can find for examples using Leaflet and Mapquest tiles gives the same sample code above but no mention of how to use the API key.

But when I look at Mapquest's documentation at https://developer.mapquest.com/documentation/leaflet-plugins/maps their example is completely different, it says to use to send the key instead of otile{s}.mqcdn.com, and to use MQ.MapLayer() in javascript to create the map layer and not L.TileLayer() passing the client url and options, as done by this extension. Am wondering if it's possible to use the key with this extension, I am really very lost and confused, any help would be so much appreciated!

tonydspaniard commented 8 years ago

According to the documentation, what you do is to setup the Tile url template as you did on the example. And after you register the map (render the widget) you also have to register the script file: <script src="http://www.mapquestapi.com/sdk/leaflet/v2.s/mq-map.js?key=KEY"></script>. Like this:

$this->registerJsFile('http://www.mapquestapi.com/sdk/leaflet/v2.s/mq-map.js?key=KEY', ['depends' => [\dosamigos\leaflet\LeaftLetAsset::className()]]); 

Be careful, 'subdomains' option should be an array: https://github.com/2amigos/yii2-leaflet-extension#usage.

Let me know how it goes.

kokoadi commented 7 years ago

has been block request direct map since July 11. 2016 how to solve this?

tonydspaniard commented 7 years ago

@kokoadi I now use the free tiles of http://stamen.com

$tileLayer = new TileLayer(
    [
        'urlTemplate' => 'http://tile.stamen.com/terrain/{z}/{x}/{y}.png',
        'clientOptions' => [
            'attribution' => 'Map tiles by <a href="http://stamen.com/">Stamen Design</a>,  ' .
                'under <a href="http://creativecommons.org/licenses/by/3.0">CC BY 3.0</a>. ' .
                'Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, ' .
                '<a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>',
            'subdomains' => ['1', '2', '3', '4'],
        ],
    ]
);
ealanisg commented 5 years ago

Is there something I must take in count on 2018 about changes on Leaflet or Tiles because I just can´t have a rendered map, I have been using the provided examples an variations on Tiles with same result:

On debug I get:

<div id="w2" style="height: 200px;"></div>

This is my code:

` use dosamigos\leaflet\types\LatLng; use dosamigos\leaflet\layers\Marker; use dosamigos\leaflet\layers\TileLayer; use dosamigos\leaflet\LeafLet; use dosamigos\leaflet\widgets\Map;

....

                    $center = new dosamigos\leaflet\types\LatLng(['lat' => 51.508, 'lng' => -0.11]);

                    // now lets create a marker that we are going to place on our map
                    $marker = new \dosamigos\leaflet\layers\Marker(['latLng' => $center, 'popupContent' => 'Hi!']);

                    // The Tile Layer (very important)
                    $tileLayer = new \dosamigos\leaflet\layers\TileLayer([
                       'urlTemplate' => 'http://tile.stamen.com/terrain/{z}/{x}/{y}.png',
                        'clientOptions' => [
                            'map' => 'map',
                            'attribution' => 'Map tiles by <a href="http://stamen.com/">Stamen Design</a>,  ' .
                                'under <a href="http://creativecommons.org/licenses/by/3.0">CC BY 3.0</a>. ' .
                                'Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, ' .
                                '<a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>',
                            'subdomains' => ['1', '2', '3', '4'],
                        ],
                    ]);

                    // now our component and we are going to configure it
                    $leaflet = new \dosamigos\leaflet\LeafLet([
                        'center' => $center, // set the center
                    ]);
                    // Different layers can be added to our map using the `addLayer` function.
                    $leaflet->addLayer($marker)      // add the marker
                            ->addLayer($tileLayer);  // add the tile layer

                    // finally render the widget
                    echo \dosamigos\leaflet\widgets\Map::widget(['leafLet' => $leaflet]);
                    Yii::info(\dosamigos\leaflet\widgets\Map::widget(['leafLet' => $leaflet]));

`