2014-06-11 4 views

답변

3

좋아,이 나는 Static Google Map에 사용자 정의를 MapBox.geojson 파일을 변환하는 방법입니다 : 이것은 내가 .geojson로 변환 된 MapBox지도입니다

지도 사용 : https://a.tiles.mapbox.com/v3/jeitnier.icm51ajc/markers.geojson. 파란색으로 채우기가 &이고 LineString 인 빨간색 획이있는 Polygon 경계가 있습니다.

당신은 사용자의 특정 요구에 맞게 일을 조정해야하지만이 요점이다

$url  = 'https://a.tiles.mapbox.com/v3/jeitnier.icm51ajc/markers.geojson'; 
$response = \Utility::curl($url); // This is just a standard cURL function that returns the contents of the JSON 
$geojson = json_decode($response); 
$paths = ''; 
$markers = ''; 

foreach ($geojson->features AS $feature) 
{ 
    $properties = array(); 

    if ('LineString' == $feature->geometry->type OR 'Polygon' == $feature->geometry->type) 
    { 
     $properties['stroke']  = substr($feature->properties->stroke, 1, 7); 
     $properties['stroke_width'] = $feature->properties->{'stroke-width'} - 1; 
    } 

    if ('LineString' == $feature->geometry->type) 
    { 
     $paths .= '&path=color:0x' . $properties['stroke'] . '99|weight:' . $properties['stroke_width']; 

     foreach ($feature->geometry->coordinates AS $set) 
     { 
      // put them in reverse order (lat/long) and convert to string 
      $paths .= '|' . $set[1] . ',' . $set[0]; 
     } 
    } 
    elseif ('Polygon' == $feature->geometry->type) 
    { 
     $properties['fill']   = substr($feature->properties->fill, 1, 7); 
     $properties['fill_opacity'] = $feature->properties->{'fill-opacity'} * 100; 

     $paths .= '&path=color:0x' . $properties['stroke'] . '|weight:' . $properties['stroke_width'] . '|fillcolor:0x' . $properties['fill'] . $properties['fill_opacity']; 

     foreach ($feature->geometry->coordinates AS $coordinate) 
     { 
      // iterate over individual coordinate set 
      foreach ($coordinate AS $set) 
      { 
       // put them in reverse order (lat/long) and convert to string 
       $paths .= '|' . $set[1] . ',' . $set[0]; 
      } 
     } 
    } 
    elseif ('Point' == $feature->geometry->type) 
    { 
     $markers .= '&markers=scale:' . $this->scale; 
     $markers .= '|' . $feature->geometry->coordinates[1] . ',' . $feature->geometry->coordinates[0]; 
    } 
} 

// set map parameters 
$params = array(
    'key' => Config::get('custom.google_map_api_key'), 
    'zoom' => 16, 
    'size' => '300x300', 
    'format' => 'png32', 
    'scale' => '2', 
    'sensor' => 'false', 
); 

$url = 'http://maps.googleapis.com/maps/api/staticmap?' . http_build_query($params) . $markers . $paths; 

코드입니다. 필자가 작성한 코드는 마커를 지원하며 다각형은 & 개의 줄만 필요했습니다.

관련 문제